1

I am trying to write a wrapper for the google adwords api in Clojure but struggle with constants and Interfaces. The java code looks like this :

CampaignServiceInterface campaignService =
    user.getService(AdWordsService.V201109.CAMPAIGN_SERVICE);

Usually you can call constants in Clojure with e.g. (Math/PI) but when I write:

(def user (AdWordsUser. ))
(.getService user (AdWordsService/V201109/CAMPAIGN_SERVICE))

I just get "no such namespace". Also I am a bit clueless on how to implement the interface correct. I think I should use "reify" but I get stuck.

Link to Interface: http://google-api-adwords-java.googlecode.com/svn-history/r234/trunk/docs/com/google/api/adwords/v201003/cm/CampaignServiceInterface.html

(defn campaign-service [ ]
(reify 
  com.google.adwords.api.v201109.cm.CampaignServiceInterface
  (get [this] ??))))
Christian Berg
  • 14,246
  • 9
  • 39
  • 44
C.A
  • 620
  • 1
  • 11
  • 23

2 Answers2

4

If I read it correctly, AdWordsService.V201109.CAMPAIGN_SERVICE is a static constant of an inner class of class AdWordsService.

To access inner classes you need to use java's internal name mangling scheme **; separate the inner class from its outer class with a $ sign:

AdWordsService$V201109/CAMPAIGN_SERVICE

** the JVM doesn't actually have a notion of inner classes, so java "fakes" it by creating a standalone class AdWordsService$V201109

Joost Diepenmaat
  • 17,633
  • 3
  • 44
  • 53
1

1.About accessing constants. Did you import AdWordsService? If not you either can access AdWordsService with fully qualified name: some.package.name.AdWordsService/V201109/CAMPAIGN_SERVICE, or import it via import macro.

2.Check examples here: http://clojuredocs.org/clojure_core/clojure.core/reify

(defn campaign-service [ ]
(reify   
  com.google.adwords.api.v201109.cm.CampaignServiceInterface
  (get [_ selector] (some-function selector))
  (mutate [_ operations] (some-function-2 operations))))
Mikita Belahlazau
  • 15,326
  • 2
  • 38
  • 43
  • Hi Nikita, yes I imported it and I will try your way. Thanks for the interface example! – C.A May 25 '12 at 08:01