adglare 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/adglare.rb +184 -2
  3. metadata +24 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 01f97eb3aaaa6ac98fd2fd458f87595c033c8d83
4
- data.tar.gz: fe73cea7cfcb637a534cc1d54cf7f3ea0d8b8323
3
+ metadata.gz: 0fe6050795335a6083055115e61ec533b8ee64bc
4
+ data.tar.gz: 0672f196c17f68e02db476b122ae8eadaf45ba1f
5
5
  SHA512:
6
- metadata.gz: b61f9249b84a84f022799f657e79add3e090b3cebf0b1eedca86c3ef4f0e20f60ccc4b55e5bfc0c8a872641a563253ad4f09e58244915907e0d2dad7538f3da3
7
- data.tar.gz: 1b1a50a73fc4e67c34acee9ee74586ddc28171ca4e2ee18b9596d17f3ae0503e90eceaddec74257a20a2cfbbc532b63dcabcc8e886f61f06a0b7f4d722e5d96c
6
+ metadata.gz: cebd853cd2f058e9c8b2f76d8aa3677fc80e3d207bc0d991d9b9563a510c5939fdfab3bb8a5152049a6326c83f1b02afb6410895e7e81964f7f3d1b16e39de09
7
+ data.tar.gz: 575cddcbbaf56a766172aaea67caa539ee9727b3bb6e6d6bdd7224f8a7dfa7b0f74536ce0aabf14251baebbcff436faa389456ba61264e7c044be5f43583ab1d
@@ -1,5 +1,187 @@
1
1
  class Adglare
2
- def self.hi
3
- puts "Hello world!"
2
+ require 'digest/sha1'
3
+ require 'curb'
4
+ require 'json'
5
+
6
+ attr_accessor :public_key, :private_key, :ajax
7
+ # If ajax is true, the class will output the required Javascript to make the API call, instead of using CURL
8
+
9
+ def initialize public_key:, private_key:, ajax:false
10
+ self.public_key = public_key
11
+ self.private_key = private_key
12
+ self.ajax = ajax
4
13
  end
14
+
15
+ # param int zgID Zone Group ID
16
+ def zonegroups_list zgID: nil
17
+ call_adglare_api 'zonegroups_list', { zgID: zgID }
18
+ end
19
+
20
+ # param string name Zone name
21
+ def zonegroups_add name:
22
+ call_adglare_api 'zonegroups_add', { name: name }
23
+ end
24
+
25
+ # param int zgID Zone Group ID
26
+ def zonegroups_delete zgID:
27
+ call_adglare_api 'zonegroups_delete', { zgID: zgID }
28
+ end
29
+
30
+ # param int zID Zone ID
31
+ # param int zgID Zone Group ID
32
+ def zones_list zID: nil, zgID: nil
33
+ call_adglare_api 'zones_list', {zId: zID, zgID: zgID}
34
+ end
35
+
36
+ # param string name Zone name
37
+ # param int zgID Zone Group ID
38
+ # param string adtype Ad type (jsonad or imagebanner)
39
+ def zones_add name:, zgID:, adtype:
40
+ call_adglare_api 'zones_add', {zgID: zgID, adtype: adtype, name: name}
41
+ end
42
+
43
+ # param int zID Zone ID
44
+ # param string name Zone name
45
+ # param string adformat The supported ad dimensions, in the format iab_000_000. Delimit and flag by a # if multiple dimensions are supported. example: #iab_468_60#iab_300_250#
46
+ # param int zgID Zone Group ID
47
+ def zones_modify zID:, name: nil, adformat: nil, zgID: nil
48
+ call_adglare_api 'zones_modify', {zID: zID, zgID: zgID, adformat: adformat, name: name}
49
+ end
50
+
51
+ # param int zID Zone ID
52
+ def zones_delete zID:
53
+ call_adglare_api 'zones_delete', {zID: zID}
54
+ end
55
+
56
+ # param int cID Campaign ID
57
+ # param int aID Advertiser ID
58
+ def campaigns_list cID: nil, aID: nil
59
+ call_adglare_api 'campaigns_list', {cID: cID, aID: aID}
60
+ end
61
+
62
+ # param string name Campaign name
63
+ def campaigns_add name:
64
+ call_adglare_api 'campaigns_add', {name: name}
65
+ end
66
+
67
+ # param int cID Campaign ID
68
+ # param array params at least one of the following:
69
+ # int aID (advertiser ID)
70
+ # string timestamp_start (can be set to "immediately") example: 2015-12-03 15:59:59
71
+ # string runsuntil example: 2015-12-03 15:59:59
72
+ # string name
73
+ # string status (active, onhold, waitingreview, completed)
74
+ # int weight (1-5)
75
+ # int tier (1 for an In-House campaign, 2 for Normal and 3 for Override)
76
+ # string displaynetwork (which zones this campaign should run. Use "#ALL#" to display in all zones, or delimit the zIDs by a # otherwise)
77
+ # string notes
78
+ # string notes_updatemethod (overwrite, append, prepend) defaults to append
79
+ def campaigns_modify cID:, params: []
80
+ call_adglare_api 'campaigns_modify', params + {cID: cID}
81
+ end
82
+
83
+
84
+ # param int cID Campaign ID
85
+ def campaigns_delete cID:
86
+ call_adglare_api 'campaigns_delete', {cID: cID}
87
+ end
88
+
89
+
90
+ # param int cID Campaign ID
91
+ def campaigns_creatives_list cID:
92
+ call_adglare_api 'campaigns_creatives_list', {cID: cID}
93
+ end
94
+
95
+
96
+ # param int cID Campaign ID
97
+ # param string creativename
98
+ # param string bannerURL The URL on which the banner can be found.
99
+ # param string targetURL The landing page URL that should be opened upon clicking
100
+ def campaigns_creatives_add cID:, creativename:, bannerURL:, targetURL:
101
+ call_adglare_api 'campaigns_creatives_add', {cID: cID, creativename: creativename, bannerURL: bannerURL, targetURL: targetURL}
102
+ end
103
+
104
+
105
+ # param int cID Campaign ID
106
+ # param int crID Campaign Creative ID
107
+ # param string creativename
108
+ # param string targetURL The landing page URL that should be opened upon clicking
109
+ def campaigns_creatives_modify cID:, crID:, creativename: nil, targetURL: nil
110
+ call_adglare_api 'campaigns_creatives_modify', {cID: cID, creativename: creativename, crID: crID, targetURL: targetURL}
111
+ end
112
+
113
+
114
+ # param int cID Campaign ID
115
+ # param int crID Campaign Creative ID
116
+ def campaigns_creatives_delete cID:, crID:
117
+ call_adglare_api 'campaigns_creatives_delete', {cID: cID, crID: crID}
118
+ end
119
+
120
+
121
+ # param int cID Campaign ID
122
+ # param string date_from The start date of the result set. Use the format YYYY-MM-DD
123
+ # param string date_until The end date of the result set. Use the format YYYY-MM-DD
124
+ def reports_campaigns date_from:, date_until:, cID: nil
125
+ call_adglare_api 'reports_campaigns', {date_from: date_from, date_until: date_until, cID: cID}
126
+ end
127
+
128
+
129
+ # param int zID Zone ID
130
+ # param string date_from The start date of the result set. Use the format YYYY-MM-DD
131
+ # param string date_until The end date of the result set. Use the format YYYY-MM-DD
132
+ def reports_zones date_from:, date_until:, zID: nil
133
+ call_adglare_api 'reports_zones', {date_from: date_from, date_until: date_until, zID: zID}
134
+ end
135
+
136
+ private
137
+
138
+ def call_adglare_api method_name, post_vars
139
+ # remove empty values from post_vars
140
+ post_vars.select! do |k, v|
141
+ v != nil
142
+ end
143
+
144
+ # add your authentication pairs
145
+ post_vars[:public_key] = self.public_key
146
+ post_vars[:nonce] = sprintf('%.0f', (Time.now.to_f * 100).round)
147
+ post_vars[:hash_method] = 'sha1'
148
+
149
+ # generate authentication hash variable
150
+ query_string = URI.encode(post_vars.map{|k,v| "#{k}=#{v}"}.join("&"))
151
+ to_be_hashed = self.private_key + '_' + query_string
152
+ hash = Digest::SHA1.hexdigest to_be_hashed
153
+ post_vars[:hash] = hash
154
+
155
+ endpoint = 'https://healthpoint.adglare.net/api/v1/'
156
+ url = endpoint + method_name
157
+
158
+ if self.ajax
159
+ query_string = URI.encode(post_vars.map{|k,v| "#{k}=#{v}"}.join("&"))
160
+ return "
161
+ $.ajax({type: 'POST', dataType: 'jsonp', url: '#{endpoint}?', data: '#{query_string}', xhrFields: {withCredentials: false}, success: function(data) {
162
+ [[callback]]
163
+ }
164
+ });"
165
+ else
166
+ # send via cURL
167
+ http = Curl.post(url, post_vars) do |http|
168
+ http.headers = false
169
+ end
170
+
171
+ content = http.body_str
172
+
173
+ # parse response into JSON object
174
+ json = JSON.parse content
175
+
176
+ if json["response"]["success"] == '1'
177
+ if json["response"]["data"]
178
+ return json["response"]["data"]
179
+ else
180
+ return json["response"]
181
+ end
182
+ else
183
+ raise StandardError json["response"]["errormsg"]
184
+ end
185
+ end
186
+ end
5
187
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adglare
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolas Connault
@@ -9,7 +9,27 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2016-10-04 00:00:00.000000000 Z
12
- dependencies: []
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: curb
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.9'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.9.3
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.9'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.9.3
13
33
  description: Allows interaction with an AdGlare account, to display ads on multiple
14
34
  sites
15
35
  email: nicolasconnault@gmail.com
@@ -36,7 +56,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
36
56
  - - ">="
37
57
  - !ruby/object:Gem::Version
38
58
  version: '0'
39
- requirements: []
59
+ requirements:
60
+ - curb 0.9+
40
61
  rubyforge_project:
41
62
  rubygems_version: 2.5.1
42
63
  signing_key: