twitter_ads 0.0.2 → 0.0.4

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 +8 -8
  2. data/lib/twitter_ads.rb +13 -152
  3. metadata +8 -8
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YjI2YjA5ZGEzNjljMDc1MzBjYjBiZjNhYWM0YzVmZjRlYWZjZmZiMg==
4
+ ZjE0ZmFmYWFmMmJiYzc5MzFjY2E5YmI5M2FjZjlmN2ViM2ZkZTQwYQ==
5
5
  data.tar.gz: !binary |-
6
- OGU1YjJmMzY1OTk1ZTkzODRhMmU2MGI2ZmY2ZDhkMDgxOTIxM2NiZg==
6
+ OWU0OGJmM2VmMGFjMWFkMDIyMjA0Zjk4NjU5NjFmYmY4NDZlYzA1NQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MDU1NTEyZWNhOWY4MmFmZTEwNGVjODM4ZjQyNjJjZmVkOTYwZTE2ZGQ4ZWUy
10
- MDM1ZDQwNGE4NzhiNzdkZmI4NTEzYTdhMDBkNDI2MTA1ZWYxYzZlNmZkNzUz
11
- ZWIxNmMwNjllN2JlYTNjNjA4NDc1NTRkNDAxY2U3NDUxY2M3NTA=
9
+ MTcwMDE4MjgwYTY3ZDgyM2Y0YWZiZWMyNjkyM2U5NmU1ZWJhNGVlNGU5ZWQy
10
+ ODUzZjIwYzk1Zjk0ZmFkZDBkZDJkNmNmMTYzZGZiZTc5Zjc0YzBlNGE2OGYx
11
+ NGYyNTg0MjFhMjM4MDJjNTMxZGFkYjRlYzQxMTk1ZTdlMmUyZTQ=
12
12
  data.tar.gz: !binary |-
13
- YjA2YTIzZTliMjUyMmQyYzc2YjllMTJkNzgyYzUwM2RlZTA3ZTQxY2Q4NDE2
14
- YTFkNzY4YTU0MDhkYzRmNTFmNDgwOTcyNWFhZGM5NTliZmZkMjI0ZTY0YjJl
15
- NzZmMWU0NzhlOGEwNDAzMTc1MGE5ODhkMGM0YTYzMGIzOWZjNWQ=
13
+ MWRlNDg0NzA2NGNjNmI4Mjg2MzM0ODgwYmQ0MjdmM2E5YmM5MThiZWZhY2Yw
14
+ YmEyODIzZjg2NGYwMjAyNzEyZTI5NzZkY2EwNzE4NTk4M2VmOWY1N2RmNTE0
15
+ MzRhMDc2YjcwZTU2MTM4NTYwMjhmMWViYTJkYTRkYmEyYzE1ZjE=
data/lib/twitter_ads.rb CHANGED
@@ -6,10 +6,9 @@
6
6
  #
7
7
  #
8
8
  require 'oauth'
9
- require 'json'
9
+ require 'multi_json'
10
+
10
11
 
11
- ADS_API_ENDPOINT="ads-api.twitter.com"
12
- TRACE=false
13
12
  # Usage:
14
13
  # Initialisation
15
14
  #
@@ -21,7 +20,7 @@ TRACE=false
21
20
  # ads.accounts
22
21
  #
23
22
  # get info on a specfic account
24
- # account=ads.account[account_id]
23
+ # account = ads.account[account_id]
25
24
  #
26
25
  # get tailored_audience change
27
26
  # accounts.tailored_audience_changes
@@ -34,155 +33,17 @@ TRACE=false
34
33
  #
35
34
  # same with post, put, delete
36
35
  #
37
- module TwitterAds
38
- UnauthorizedAccess="UNAUTHORIZED_ACCESS"
39
- class AdsError < StandardError
40
- end
41
-
42
- # Common class to manage access to recourse
43
- # Need access to client, prefix, and ops available on this ressource
44
- #
45
- # provide operation oauth autenthificated operation (get/post/put/delete)
46
- # as well as dynamically discovered opertions, using the ops instance variable
47
- #
48
- class RestRessource
49
- @prefix=""
50
- attr:access_token,:prefix
51
-
52
- # Utility funciton to do a get on the RES API
53
- def get action = "" , params = nil
54
- do_request :get,action,params
55
- end
56
- def post action , params = nil
57
- do_request :post,action,params
58
- end
59
- def put action , params = nil
60
- do_request :put,action,params
61
- end
62
- def delete action = "", params = nil
63
- do_request :delete,action,params
64
- end
65
-
66
- def do_request verb,action,params
67
- url="https://#{ADS_API_ENDPOINT}/0/#{prefix}#{action}"
68
- if url[-1] == "/" then url = url[0..-2] end
69
- puts "Doing request:#{verb} #{prefix} #{action} #{params} URL:#{url}" if TRACE
70
- res=::JSON.parse @client.access_token.request(verb,url,params).body
71
- if res["errors"]
72
- raise AdsError,res["errors"].first["code"]
73
- end
74
- res["data"]
75
- end
76
-
77
-
78
-
79
- # Dynamic check of methods
80
- # tab_ops contain the list of allowed method and verbs
81
- # prefix the prefix to add to the method
82
- #
83
- def check_method tab_ops,prefix,method_sym,do_call,*arguments, &block
84
- method_sym = method_sym.id2name
85
- verb=:get
86
- [:post,:get,:delete,:put].each do |averb|
87
- if method_sym.start_with? averb.id2name
88
- verb = averb
89
- method_sym[averb.id2name+"_"]=""
90
- break
91
- end
92
- end
93
- if tab_ops[verb].include? method_sym.to_sym
94
- if do_call
95
- method = prefix+method_sym
96
- params = arguments.first
97
- if params.first && params.first.class!=Hash
98
- method += "/#{params.shift}"
99
- end
100
- return do_request verb,method,params.shift
101
- else
102
- return nil
103
- end
104
- end
105
- nil
106
- end
107
- def method_missing(method_sym, *arguments, &block)
108
- # the first argument is a Symbol, so you need to_s it if you want to pattern match
109
- if (res = check_method(@ops,"",method_sym,true,arguments,block))==nil
110
- super
111
- else
112
- res
113
- end
114
- end
115
- def respond_to? method_sym
116
- if check_method(@ops,"",method_sym.to_sym,false,"",nil)
117
- return true
118
- end
119
- super
120
- end
121
- end
122
-
123
- class Client < RestRessource
124
- attr_reader :config,:access_token,:ops
125
36
 
126
- def initialize params
127
- @config=params
128
- @ops={:get=>[:bidding_rules,:iab_categories]}
129
-
130
- consumer = OAuth::Consumer.new(
131
- params[:consumer_key],params[:consumer_secret],
132
- :site => "https://#{ADS_API_ENDPOINT}")
133
- consumer.http.use_ssl = true
134
- consumer.http.set_debug_output(STDERR)
135
- consumer.http.verify_mode = OpenSSL::SSL::VERIFY_NONE
136
- @client=self # To manage rest resource
137
- @access_token = OAuth::AccessToken.new(consumer, params[:access_token],params[:access_secret])
138
- end
139
-
140
- # return the list of available accounts
141
- def accounts
142
- if !@cached_accounts
143
- @cached_accounts = get("accounts").map{|account| Account.new(self,account)}
144
- end
145
- @cached_accounts
146
- end
147
-
148
- # Create an account based on his id
149
- def account account_id
150
- TwitterAds::Account.new(self,{"id"=>account_id})
151
- end
152
-
153
- end
154
-
155
- class Account < RestRessource
156
-
157
- attr_reader :id,:name
158
- def initialize client,account
159
- @client = client
160
- @account = account
161
- init
162
- @prefix = "accounts/#{@id}/"
163
- @ops ={:get =>[:promoted_accounts,:promoted_tweets,:tailored_audience_changes,
164
- :targeting_criteria,:app_lists,:campaigns,:funding_instruments,
165
- :line_items,:promoted_accounts,:promotable_users,:reach_estimate,
166
- :targeting_suggestions],
167
- :post =>[:tailored_audiences,:tailored_audience_changes,:campaigns],
168
- :put =>[:campaigns,:promoted_tweets,:targeting_criteria,"tailored_audiences__global_opt_out"],
169
- :delete=>[:tailored_audiences,:campaigns,:promoted_tweets,:targeting_criteria]
170
- }
171
-
172
- end
173
- def init
174
- @id = @account["id"]
175
- @name = @account["name"]
176
- end
177
-
178
- def as_json
179
- return @account
180
- end
37
+ module TwitterAds
181
38
 
182
- def refresh
183
- @account = get("")
184
- init
185
- end
39
+ ADS_API_ENDPOINT = 'ads-api.twitter.com'
40
+ TRACE = true
41
+ UnauthorizedAccess = 'UNAUTHORIZED_ACCESS'
42
+ class AdsError < StandardError
43
+ end
186
44
 
187
- end
188
45
  end
46
+ require "twitter_ads/rest_ressource"
47
+ require "twitter_ads/client"
48
+ require "twitter_ads/account"
49
+ require "twitter_ads/tailored_audience"
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twitter_ads
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Landspurg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-02 00:00:00.000000000 Z
11
+ date: 2015-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oauth
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '0.4'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '0.4'
27
27
  description: ! ' '
28
28
  email: thomas@seevibes.com
29
29
  executables: []
@@ -31,7 +31,7 @@ extensions: []
31
31
  extra_rdoc_files: []
32
32
  files:
33
33
  - lib/twitter_ads.rb
34
- homepage: http://rubygems.org/gems/twitter_ads
34
+ homepage: https://github.com/seevibes/twitter_ads
35
35
  licenses:
36
36
  - MIT
37
37
  metadata: {}
@@ -43,7 +43,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - ! '>='
45
45
  - !ruby/object:Gem::Version
46
- version: '0'
46
+ version: 1.9.3
47
47
  required_rubygems_version: !ruby/object:Gem::Requirement
48
48
  requirements:
49
49
  - - ! '>='