pomade 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
@@ -0,0 +1,2 @@
1
+ --markup markdown
2
+ lib/**/*.rb
data/Gemfile CHANGED
@@ -1,4 +1,10 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in pomade.gemspec
4
3
  gemspec
4
+
5
+ gem 'rake'
6
+
7
+ group :test do
8
+ gem 'i18n'
9
+ gem 'tzinfo'
10
+ end
data/Rakefile CHANGED
@@ -1 +1,21 @@
1
- require "bundler/gem_tasks"
1
+ require 'rubygems'
2
+ require 'bundler/gem_tasks'
3
+
4
+ # ----- Utility Functions -----
5
+
6
+ def scope(path)
7
+ File.join(File.dirname(__FILE__), path)
8
+ end
9
+
10
+ # ----- Default: Testing -----
11
+
12
+ task :default => :test
13
+
14
+ require 'rake/testtask'
15
+
16
+ Rake::TestTask.new do |t|
17
+ t.libs << 'test'
18
+ test_files = FileList[scope('test/test_*.rb')]
19
+ t.test_files = test_files
20
+ t.verbose = true
21
+ end
@@ -2,6 +2,9 @@ module Pomade
2
2
  # Errors thrown from Pomegranate
3
3
  class ResponseError < StandardError; end
4
4
 
5
+ # Cannot authenticate
6
+ class AuthenticationError < StandardError; end
7
+
5
8
  # If an asset's keys do not match up
6
9
  class InvalidAssetKeys < StandardError; end
7
10
 
@@ -7,88 +7,164 @@ module Pomade
7
7
  # Handles all interactions to Pomegranate.
8
8
  class Publisher
9
9
  ##
10
- # Creates a new instance of +Publisher+ that pushes records to Pomegranate.
10
+ # Creates a new instance of `Publisher` that pushes records to Pomegranate. If you do not set any optional arguments, Pomade will connect to Pomegranate's public sandbox instance.
11
11
  #
12
- # == Parameters
12
+ # ## Parameters
13
13
  #
14
- # * *subdomain* _(string)_ - The subdomain for the Pomegranate instance that you'd like to connect to.
15
- # * *username* _(string)_ - The username used for connecting to your isntance.
16
- # * *password* _(string)_ - The password used for connecting to your isntance.
17
- # * *client_id* _(string)_ - Your client ID.
18
- # * *opts* _(hash, optional)_ - Additional options. Available options are:
19
- # * *:host* _(string)_ - The host (domain name) that your Pomegranate instance lives on.
20
- # * *:pathname* _(string)_ - The path that is used for interacting with assets.
21
- # * *:time_format* _(strftime)_ - Change the layout of the timestamp that is posted to your instance.
22
- # * *:domain* _(string)_ - NTLM login domain.
14
+ # * **args** _(hash, optional)_
15
+ # * **:subdomain** _(string)_ -- The subdomain for the Pomegranate instance that you'd like to connect to.
16
+ # * **:username** _(string)_ -- The username used for connecting to your isntance.
17
+ # * **:password** _(string)_ -- The password used for connecting to your isntance.
18
+ # * **:client_id** _(string)_ -- Your client ID.
19
+ # * **:skip_authentication** _(string)_ -- Skip any authentication tests
20
+ # * **:host** _(string)_ -- The host (domain name) that your Pomegranate instance lives on.
21
+ # * **:pathname** _(string)_ -- The path that is used for interacting with assets.
22
+ # * **:time_format** _(strftime)_ -- Change the layout of the timestamp that is posted to your instance.
23
+ # * **:domain** _(string)_ -- NTLM login domain.
23
24
  #
24
- # == Returns
25
- # An instance of +Pomade::Publisher+
25
+ # ## Returns
26
26
  #
27
- # == Example
27
+ # An instance of `Pomade::Publisher`
28
+ #
29
+ # ## Example
28
30
  #
29
- # @pom = Pomade::Publisher.new('my-subdomain', 'myusername', 'mypassword', 'XX')
30
- def initialize(subdomain, username, password, client_id, opts = {})
31
- @subdomain = subdomain
32
- @username = username
33
- @password = password
34
- @client_id = client_id
31
+ # @pom = Pomade::Publisher.new('my-subdomain', 'myusername', 'mypassword', 'XX')
32
+ def initialize(args = {})
33
+ @subdomain = args[:subdomain] || 'pomegranate'
34
+ @username = args[:username] || nil
35
+ @password = args[:password] || nil
36
+ @client_id = args[:client_id] || 'P0'
35
37
 
36
38
  # Other options
37
39
  @options = {}
38
- @options[:host] = opts[:host] || 'timessquare2.com'
39
- @options[:pathname] = opts[:pathname] || '/p/p.svc/Assets/'
40
- @options[:time_format] = opts[:time_format] || "%Y-%m-%dT%H:%M:%SZ"
41
- @options[:domain] = opts[:domain] || nil
40
+ @options[:skip_authentication] = args[:skip_authentication] || false
41
+ @options[:host] = args[:host] || 'timessquare2.com'
42
+ @options[:pathname] = args[:pathname] || '/p/p.svc/Assets/'
43
+ @options[:time_format] = args[:time_format] || "%Y-%m-%dT%H:%M:%SZ"
44
+ @options[:domain] = args[:domain] || nil
45
+
46
+ # Test authentication
47
+ test_authentication! unless @options[:skip_authentication]
42
48
  end
43
49
 
44
50
  ##
45
- # Publishes an array of assets to Pomegranate and returns the results in a +hash+.
51
+ # Sets authentication credentials
52
+ #
53
+ # ## Parameters
46
54
  #
47
- # == Parameters
55
+ # * **credentials** _(hash)_
56
+ # * **:subdomain** _(string)_ -- The subdomain for the Pomegranate instance that you'd like to connect to.
57
+ # * **:username** _(string)_ -- The username used for connecting to your isntance.
58
+ # * **:password** _(string)_ -- The password used for connecting to your isntance.
59
+ # * **:client_id** _(string)_ -- Your client ID.
60
+ #
61
+ # ## Returns
48
62
  #
49
- # * *assets* _(array)_ - A collection of assets. Each item consists of a hash with three keys: +:target+, +:type+ and +:value+. The values for keys +:target+ and +:value+ are both strings while the +:type+ key's value is a symbol. Available values are:
50
- # * +:image+ -- An +IMAGE+ type asset
51
- # * +:video+ -- A +VIDEO+ type asset
52
- # * +:text+ -- A +TEXT+ type asset
63
+ # A `boolean` depending on whether the authentication passed or failed.
53
64
  #
54
- # == Returns
65
+ # ## Example
55
66
  #
56
- # A +hash+ containing two keys: +record_id+ and +assets+.
67
+ # credz = {
68
+ # username: "myuser",
69
+ # password: "mypass",
70
+ # subdomain: "mysubdomain",
71
+ # client_id: "XX"
72
+ # }
73
+ # @pom.authenticate(opts)
74
+ # # => true
75
+ def authenticate(credentials)
76
+ @subdomain = credentials[:subdomain] || @subdomain
77
+ @username = credentials[:username] || @username
78
+ @password = credentials[:password] || @password
79
+ @client_id = credentials[:client_id] || @client_id
80
+
81
+ test_authentication unless @options[:skip_authentication]
82
+ end
83
+
84
+ ##
85
+ # Check if authentication is set
86
+ def authentication_set?
87
+ !@username.nil? && !@password.nil?
88
+ end
89
+
90
+ ##
91
+ # Performs a GET request on the Pomegranate instance's feed to ensure login credentials are correct.
92
+ def test_authentication
93
+ status = false
94
+
95
+ Net::HTTP.start("#{@subdomain}.#{@options[:host]}", 80) do |http|
96
+ req = Net::HTTP::Get.new(@options[:pathname])
97
+
98
+ if authentication_set?
99
+ req.ntlm_auth(@username, @options[:domain], @password)
100
+ end
101
+
102
+ response = http.request(req)
103
+
104
+ if response.code.to_i.between?(200,399)
105
+ status = true
106
+ else
107
+ status = false
108
+ end
109
+ end
110
+
111
+ return status
112
+ end
113
+
114
+ ##
115
+ # Raises AuthenticationError if authentication fails
116
+ def test_authentication!
117
+ raise AuthenticationError unless test_authentication
118
+ end
119
+
120
+ ##
121
+ # Publishes an array of assets to Pomegranate and returns the results in a `hash`.
122
+ #
123
+ # ## Parameters
124
+ #
125
+ # * **assets** _(array)_ -- A collection of assets. Each item consists of a hash with three keys: `:target`, `:type` and `:value`. The values for keys `:target` and `:value` are both strings while the `:type` key's value is a symbol. Available values are:
126
+ # * `:image` -- An `IMAGE type asset
127
+ # * `:video` -- A `VIDEO` type asset
128
+ # * `:text` -- A `TEXT` type asset
57
129
  #
58
- # == Example
130
+ # ## Returns
59
131
  #
60
- # records = [
61
- # { target: "XX~username", type: :text, value: "jakebellacera"},
62
- # { target: "XX~avatar", type: :image, value: "http://www.gravatar.com/avatar/98363013aa1237798130bc0fd2c4159d.png"}
63
- # ]
64
- #
65
- # @pom.publish(records)
66
- # # =>
67
- # {
68
- # record_id: "XX-91c8071a-1201-4f99-bc9d-f8d53a947dc1",
69
- # assets: [
70
- # {
71
- # "AssetID" => "9a24c8e2-1066-42fb-be1c-697c5ead476d",
72
- # "AssetData" => "jakebellacera",
73
- # "AssetType" => "TEXT",
74
- # "Target" => "XX~username",
75
- # "Client" => "XX",
76
- # "Status" => "APPROVED",
77
- # "AssetMeta" => "",
78
- # "AssetRecordID" => "XX-91c8071a-1201-4f99-bc9d-f8d53a947dc1"
79
- # },
80
- # {
81
- # "AssetID" => "9a24c8e2-1066-42fb-be1c-697c5ead476d",
82
- # "AssetData" => "http://www.gravatar.com/avatar/98363013aa1237798130bc0fd2c4159d.png",
83
- # "AssetType" => "IMAGE",
84
- # "Target" => "XX~avatar",
85
- # "Client" => "XX",
86
- # "Status" => "APPROVED",
87
- # "AssetMeta" => "",
88
- # "AssetRecordID" => "XX-91c8071a-1201-4f99-bc9d-f8d53a947dc1"
89
- # }
132
+ # A `hash` containing two keys: `record_id` and `assets`.
133
+ #
134
+ # ## Example
135
+ #
136
+ # assets = [
137
+ # { target: "PUB~1text", type: :text, value: "jakebellacera" },
138
+ # { target: "PUB~1image", type: :image, value: "http://www.gravatar.com/avatar/98363013aa1237798130bc0fd2c4159d.png" }
90
139
  # ]
91
- # }
140
+ #
141
+ # @pom.publish(records)
142
+ # # =>
143
+ # {
144
+ # record_id: "P0-91c8071a-1201-4f99-bc9d-f8d53a947dc1",
145
+ # assets: [
146
+ # {
147
+ # "AssetID" => "9a24c8e2-1066-42fb-be1c-697c5ead476d",
148
+ # "AssetData" => "jakebellacera",
149
+ # "AssetType" => "TEXT",
150
+ # "Target" => "PUB~1text",
151
+ # "Client" => "P0",
152
+ # "Status" => "UPLOADED",
153
+ # "AssetMeta" => "",
154
+ # "AssetRecordID" => "P0-91c8071a-1201-4f99-bc9d-f8d53a947dc1"
155
+ # },
156
+ # {
157
+ # "AssetID" => "9a24c8e2-1066-42fb-be1c-697c5ead476c",
158
+ # "AssetData" => "http://www.gravatar.com/avatar/98363013aa1237798130bc0fd2c4159d.png",
159
+ # "AssetType" => "IMAGE",
160
+ # "Target" => "PUB~1image",
161
+ # "Client" => "P0",
162
+ # "Status" => "UPLOADED",
163
+ # "AssetMeta" => "",
164
+ # "AssetRecordID" => "P0-91c8071a-1201-4f99-bc9d-f8d53a947dc1"
165
+ # }
166
+ # ]
167
+ # }
92
168
  def publish(assets)
93
169
  @record_id = generate_record_id
94
170
  @time = Time.now.strftime(@options[:time_format])
@@ -108,30 +184,30 @@ module Pomade
108
184
  ##
109
185
  # Validates an array of assets.
110
186
  #
111
- # == Parameters
187
+ # ## Parameters
112
188
  #
113
- # * *assets* _(array)_ - A collection of assets. Each item consists of a hash with three keys: +:target+, +:type+ and +:value+. The values for keys +:target+ and +:value+ are both strings while the +:type+ key's value is a symbol. Available values are:
114
- # * +:image+ -- An +IMAGE+ type asset
115
- # * +:video+ -- A +VIDEO+ type asset
116
- # * +:text+ -- A +TEXT+ type asset
189
+ # * **assets** _(array)_ -- A collection of assets. Each item consists of a hash with three keys: `:target`, `:type` and `:value`. The values for keys `:target` and `:value` are both strings while the `:type` key's value is a symbol. Available values are:
190
+ # * `:image` -- An `IMAGE` type asset
191
+ # * `:video` -- A `VIDEO` type asset
192
+ # * `:text` -- A `TEXT` type asset
117
193
  #
118
- # == Returns
194
+ # ## Returns
119
195
  #
120
- # The +array+ of assets.
196
+ # The `array` of assets.
121
197
  #
122
- # == Example
198
+ # ## Example
123
199
  #
124
- # records = [
125
- # { target: "XX~USERNAME", type: :text, value: "jakebellacera"},
126
- # { target: "XX~AVATAR", type: :image, value: "http://www.gravatar.com/avatar/98363013aa1237798130bc0fd2c4159d.png"}
127
- # ]
128
- #
129
- # @pom.validate(records)
130
- # # =>
131
- # [
132
- # { target: "XX~USERNAME", type: :text, value: "jakebellacera"},
133
- # { target: "XX~AVATAR", type: :image, value: "http://www.gravatar.com/avatar/98363013aa1237798130bc0fd2c4159d.png"}
134
- # ]
200
+ # assets = [
201
+ # { target: "PUB~1text", type: :text, value: "jakebellacera" },
202
+ # { target: "PUB~1image", type: :image, value: "http://www.gravatar.com/avatar/98363013aa1237798130bc0fd2c4159d.png" }
203
+ # ]
204
+ #
205
+ # @pom.validate(records)
206
+ # # =>
207
+ # [
208
+ # { target: "PUB~1text", type: :text, value: "jakebellacera" },
209
+ # { target: "PUB~1image", type: :image, value: "http://www.gravatar.com/avatar/98363013aa1237798130bc0fd2c4159d.png" }
210
+ # ]
135
211
  def validate(assets)
136
212
  available_keys = [:target, :type, :value].sort
137
213
 
@@ -142,16 +218,48 @@ module Pomade
142
218
  end
143
219
  end
144
220
 
221
+ ##
222
+ # Checks if the assets are valid or not.
223
+ #
224
+ # ## Parameters
225
+ #
226
+ # * **assets** _(array)_ -- A collection of assets. Each item consists of a hash with three keys: `:target`, `:type` and `:value`. The values for keys `:target` and `:value` are both strings while the `:type` key's value is a symbol. Available values are:
227
+ # * `:image` -- An `IMAGE` type asset
228
+ # * `:video` -- A `VIDEO` type asset
229
+ # * `:text` -- A `TEXT` type asset
230
+ #
231
+ # ## Returns
232
+ #
233
+ # A `boolean` depending on if the assets pass or fail validation.
234
+ #
235
+ # ## Example
236
+ #
237
+ # assets = [
238
+ # { target: "PUB~1text", type: :text, value: "jakebellacera" },
239
+ # { target: "PUB~1image", type: :image, value: "http://www.gravatar.com/avatar/98363013aa1237798130bc0fd2c4159d.png" }
240
+ # ]
241
+ #
242
+ # @pom.valid?(records)
243
+ # # => true
244
+ def valid?(assets)
245
+ begin
246
+ validate(assets)
247
+ return true
248
+ rescue
249
+ return false
250
+ end
251
+ end
252
+
145
253
  private
146
254
 
147
255
  ##
148
- # Generates a +SecureRandom.uuid+ (GUID) with the +client_id+ appended to it.
256
+ # Generates a `SecureRandom.uuid` (GUID) with the `client_id` appended to it.
149
257
  def generate_record_id
150
258
  @client_id + '-' + SecureRandom.uuid
151
259
  end
152
260
 
153
261
  ##
154
- # Tests to see if an asset's +:value+ is correct in correlation to its +:type+.
262
+ # Tests to see if an asset's `:value` is correct in correlation to its `:type`.
155
263
  def test(asset)
156
264
  # If the value is a URL...
157
265
  if (asset[:type] == :image || asset[:type] == :video) && url?(asset[:value])
@@ -166,15 +274,15 @@ module Pomade
166
274
  ##
167
275
  # Posts an XML to the Pomegranate instance and handles the response.
168
276
  #
169
- # *Note:* This method will fail if any requests are rejected.
277
+ # **Note:** This method will fail if any requests are rejected.
170
278
  #
171
- # == Parameters
279
+ # ## Parameters
172
280
  #
173
- # * *body* _(string, XML)_ - A Pomegranate XML asset
281
+ # * **body** _(string, XML)_ -- A Pomegranate XML asset
174
282
  #
175
- # == Returns
283
+ # ## Returns
176
284
  #
177
- # An +array+ of comiled Pomegranate assets
285
+ # An `array` of comiled Pomegranate assets
178
286
  def post(data)
179
287
  response_data = []
180
288
  data.each do |xml|
@@ -201,9 +309,9 @@ module Pomade
201
309
  ##
202
310
  # Sends a request to Pomegranate
203
311
  #
204
- # == Parameters
312
+ # ## Parameters
205
313
  #
206
- # * *body* _(string, XML)_ - A Pomegranate XML asset
314
+ # * *body* _(string, XML)_ -- A Pomegranate XML asset
207
315
  def send_request(body)
208
316
  status = false
209
317
  data = false
@@ -215,7 +323,10 @@ module Pomade
215
323
  req.content_type = 'application/atom+xml'
216
324
  req.content_length = body.size - 20 # Currently a bug with the Pomegranate API I believe
217
325
  req.body = body
218
- req.ntlm_auth(@username, @options[:domain], @password)
326
+
327
+ if authentication_set?
328
+ req.ntlm_auth(@username, @options[:domain], @password)
329
+ end
219
330
 
220
331
  response = http.request(req)
221
332
 
@@ -255,7 +366,7 @@ module Pomade
255
366
  <d:AssetRecordID>#{@record_id}</d:AssetRecordID>
256
367
  <d:Target>#{target}</d:Target>
257
368
  <d:Client>#{@client_id}</d:Client>
258
- <d:Status>APPROVED</d:Status>
369
+ <d:Status>#{@client_id == "P0" ? "UPLOADED" : "APPROVED"}</d:Status>
259
370
  </m:properties>
260
371
  </content>
261
372
  </entry>
@@ -1,3 +1,3 @@
1
1
  module Pomade
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
data/readme.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # Pomade - The ruby Pomegranate API wrapper
2
2
 
3
- Pomade is a gem that acts as an API wrapper used for interfacing with TimesSquare2's [Pomegranate API](http://api.timessquare2.com/pomegranate/).
3
+ Pomade is a ruby library that acts as an API wrapper used for interfacing with TimesSquare2's [Pomegranate API](http://api.timessquare2.com/pomegranate/).
4
4
 
5
5
  ## Installation
6
6
 
7
7
  Add this line to your application's Gemfile:
8
8
 
9
- gem 'pomade'
9
+ gem 'pomade', '~> 0.2.2'
10
10
 
11
11
  And then execute:
12
12
 
@@ -18,79 +18,124 @@ Or install it yourself as:
18
18
 
19
19
  ## Publisher
20
20
 
21
- Publisher lets you publish content to the Pomegranate API.
21
+ _View the full documentation [here](http://rdoc.info/github/jakebellacera/pomade/master/Pomade/Publisher)_
22
+
23
+ Publisher lets you easily publish content to the Pomegranate API. It handles everything from authenticating your requests to building XML files, so all you need to worry about is the content.
22
24
 
23
25
  ```ruby
24
- Pomade::Publisher.new(subdomain, username, password, client_id, options)
25
- ```
26
+ @pom = Pomade::Publisher.new
26
27
 
27
- #### Available Options
28
+ assets = [
29
+ { target: "PUB~1text", type: :text, value: "jakebellacera" },
30
+ { target: "PUB~1image", type: :image, value: "http://www.gravatar.com/avatar/98363013aa1237798130bc0fd2c4159d.png" }
31
+ ]
28
32
 
29
- These are the available options and their defaults.
33
+ record = @pom.publish(assets)
30
34
 
31
- ```ruby
35
+ puts record
36
+ # =>
32
37
  {
33
- host: 'timessquare2.com', # [string] The host (domain name) that Pomegranate lives on.
34
- pathname: '/p/p.svc/Assets/', # [string] The path that is used for interacting with Pomegranate.
35
- time_format: "%Y-%m-%dT%H:%M:%SZ", # [string] (strftime) change the layout of the timestamp.
36
- login_domain: nil # [string] NTLM login domain.
38
+ record_id: "P0-91c8071a-1201-4f99-bc9d-f8d53a947dc1",
39
+ assets: [
40
+ {
41
+ "AssetID" => "9a24c8e2-1066-42fb-be1c-697c5ead476d",
42
+ "AssetData" => "jakebellacera",
43
+ "AssetType" => "TEXT",
44
+ "Target" => "PUB~1text",
45
+ "Client" => "P0",
46
+ "Status" => "UPLOADED",
47
+ "AssetMeta" => "",
48
+ "AssetRecordID" => "P0-91c8071a-1201-4f99-bc9d-f8d53a947dc1"
49
+ },
50
+ {
51
+ "AssetID" => "9a24c8e2-1066-42fb-be1c-697c5ead476d",
52
+ "AssetData" => "http://www.gravatar.com/avatar/98363013aa1237798130bc0fd2c4159d.png",
53
+ "AssetType" => "IMAGE",
54
+ "Target" => "PUB~1image",
55
+ "Client" => "P0",
56
+ "Status" => "UPLOADED",
57
+ "AssetMeta" => "",
58
+ "AssetRecordID" => "P0-91c8071a-1201-4f99-bc9d-f8d53a947dc1"
59
+ }
60
+ ]
37
61
  }
38
62
  ```
39
63
 
40
64
  ### Usage
41
65
 
42
- To publish assets to Pomegranate, simply create a new `Pomade::Publisher` instance.
66
+ To publish assets to Pomegranate, simply create a new Publisher instance (for available options, [go here](http://rdoc.info/github/jakebellacera/pomade/master/Pomade/Publisher:initialize)).
43
67
 
44
68
  ```ruby
45
- @pom = Pomade::Publisher.new('my-subdomain', 'myusername', 'mypassword', 'XX')
69
+ @pom = Pomade::Publisher.new
46
70
  ```
47
71
 
48
- Next, you'll want to push your assets to Pomegranate. You can do this by building an array of hashes. Each item in the array represents a single asset and they each have three keys: **:target**, **:type** and **:value**. You'll pass this array into the `publish` method.
72
+ Next, you'll need to publish your assets. An asset is a `hash` that consists of three keys: **:target**, **:type** and **:value**.
49
73
 
50
74
  ```ruby
51
75
  assets = [
52
- { target: "XX~username", type: :text, value: "jakebellacera"},
53
- { target: "XX~avatar", type: :image, value: "http://www.gravatar.com/avatar/98363013aa1237798130bc0fd2c4159d.png"}
76
+ { target: "PUB~1text", type: :text, value: "jakebellacera" },
77
+ { target: "PUB~1image", type: :image, value: "http://www.gravatar.com/avatar/98363013aa1237798130bc0fd2c4159d.png" }
54
78
  ]
55
79
 
56
80
  record = @pom.publish(assets)
57
81
  ```
58
82
 
59
- The `publish` method will return a **record**. A record is a hash with two keys: **:record_id** and **:assets**. The `:record_id` is a randomly generated UUID string with your client_id prepended to it while the `:assets` array is the posted assets.
83
+ Once the publishing is complete, Publisher will return the finalized record data.
60
84
 
61
85
  ```ruby
62
86
  puts record
63
- #=>
87
+ # =>
64
88
  {
65
- record_id: "XX-91c8071a-1201-4f99-bc9d-f8d53a947dc1",
89
+ record_id: "P0-91c8071a-1201-4f99-bc9d-f8d53a947dc1",
66
90
  assets: [
67
91
  {
68
92
  "AssetID" => "9a24c8e2-1066-42fb-be1c-697c5ead476d",
69
93
  "AssetData" => "jakebellacera",
70
94
  "AssetType" => "TEXT",
71
- "Target" => "XX~username",
72
- "Client" => "XX",
73
- "Status" => "APPROVED",
95
+ "Target" => "PUB~1text",
96
+ "Client" => "P0",
97
+ "Status" => "UPLOADED",
74
98
  "AssetMeta" => "",
75
- "AssetRecordID" => "XX-91c8071a-1201-4f99-bc9d-f8d53a947dc1"
99
+ "AssetRecordID" => "P0-91c8071a-1201-4f99-bc9d-f8d53a947dc1"
76
100
  },
77
101
  {
78
- "AssetID" => "9a24c8e2-1066-42fb-be1c-697c5ead476d",
102
+ "AssetID" => "9a24c8e2-1066-42fb-be1c-697c5ead476c",
79
103
  "AssetData" => "http://www.gravatar.com/avatar/98363013aa1237798130bc0fd2c4159d.png",
80
104
  "AssetType" => "IMAGE",
81
- "Target" => "XX~avatar",
82
- "Client" => "XX",
83
- "Status" => "APPROVED",
105
+ "Target" => "PUB~1image",
106
+ "Client" => "P0",
107
+ "Status" => "UPLOADED",
84
108
  "AssetMeta" => "",
85
- "AssetRecordID" => "XX-91c8071a-1201-4f99-bc9d-f8d53a947dc1"
109
+ "AssetRecordID" => "P0-91c8071a-1201-4f99-bc9d-f8d53a947dc1"
86
110
  }
87
111
  ]
88
112
  }
89
113
  ```
90
114
 
115
+ #### Authentication
116
+
117
+ If you require authentication, you can authenticate either at initialization or by running the `authenticate` method. Publisher will attempt to authenticate with Pomegranate. Since this is a setter method, you can authenticate as many times as you'd like throughout your application.
118
+
119
+ ```ruby
120
+ credz = {
121
+ username: "myuser",
122
+ password: "mypass",
123
+ subdomain: "mysubdomain",
124
+ client_id: "XX"
125
+ }
126
+ @pom.authenticate(opts)
127
+ # => true
128
+ ```
129
+
91
130
  #### Validation
92
131
 
93
- Once you attempt to publish your assets, `Publisher` will attempt to validate your assets. Most of the time it will work, as Publisher will check your URLS for :image and :video types and ensure that they resolve properly. This validation may not find everything and you'll still get a bad response from Pomegranate, if that's the case, please [file a bug](http://github.com/jakebellacera/pomade/issues) with the steps you took to reproduce the problem.
132
+ Once you attempt to publish your assets, Publisher will attempt to validate your assets. Most of the time it will work, as Publisher will check your URLS if the asset's type is :image and :video and ensure that they resolve properly. This validation may not find everything and you'll still get a bad response from Pomegranate. If that's the case, please [file a bug](http://github.com/jakebellacera/pomade/issues) with the steps you took to reproduce the problem.
133
+
134
+ You can also run a validation manually by running the `validate(assets)` method where `assets` is your array of assets to check against.
135
+
136
+ ## More Info
137
+
138
+ Need more info? Check the [docs](http://rdoc.info/github/jakebellacera/pomade/master/frames) or [browse the source](http://github.com/jakebellacera/pomade).
94
139
 
95
140
  ## Contributing
96
141
 
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ Bundler.setup(:default, :test)
4
+ Bundler.require(:default, :test)
5
+
6
+ dir = File.dirname(File.expand_path(__FILE__))
7
+ $LOAD_PATH.unshift dir + '/../lib'
8
+ $TESTING = true
9
+ require 'test/unit'
10
+ require 'pomade'
11
+ require 'tzinfo'
@@ -0,0 +1,22 @@
1
+ require 'test_helper'
2
+
3
+ # Fixtures
4
+ $valid_assets = [
5
+ { target: "XX~username", type: :text, value: "jakebellacera"},
6
+ { target: "XX~avatar", type: :image, value: "http://www.gravatar.com/avatar/98363013aa1237798130bc0fd2c4159d.png"}
7
+ ]
8
+
9
+ class PublisherTest < Test::Unit::TestCase
10
+ def test_public_authentication
11
+ pom = Pomade::Publisher.new
12
+ assert pom.test_authentication
13
+ end
14
+
15
+ def test_asset_validation
16
+ pom = Pomade::Publisher.new
17
+
18
+ assert_nothing_raised do
19
+ pom.validate($valid_assets)
20
+ end
21
+ end
22
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pomade
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-27 00:00:00.000000000 Z
12
+ date: 2012-09-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ruby-ntlm
@@ -51,6 +51,8 @@ extensions: []
51
51
  extra_rdoc_files: []
52
52
  files:
53
53
  - .gitignore
54
+ - .travis.yml
55
+ - .yardopts
54
56
  - Gemfile
55
57
  - LICENSE.txt
56
58
  - Rakefile
@@ -60,6 +62,8 @@ files:
60
62
  - lib/pomade/version.rb
61
63
  - pomade.gemspec
62
64
  - readme.md
65
+ - test/test_helper.rb
66
+ - test/test_publisher.rb
63
67
  homepage: http://github.com/jakebellacera/pomade
64
68
  licenses: []
65
69
  post_install_message:
@@ -72,17 +76,24 @@ required_ruby_version: !ruby/object:Gem::Requirement
72
76
  - - ! '>='
73
77
  - !ruby/object:Gem::Version
74
78
  version: '0'
79
+ segments:
80
+ - 0
81
+ hash: 1927956313076339663
75
82
  required_rubygems_version: !ruby/object:Gem::Requirement
76
83
  none: false
77
84
  requirements:
78
85
  - - ! '>='
79
86
  - !ruby/object:Gem::Version
80
87
  version: '0'
88
+ segments:
89
+ - 0
90
+ hash: 1927956313076339663
81
91
  requirements: []
82
92
  rubyforge_project:
83
93
  rubygems_version: 1.8.24
84
94
  signing_key:
85
95
  specification_version: 3
86
96
  summary: Ruby wrapper for TimesSquare2's Pomegranate API
87
- test_files: []
88
- has_rdoc:
97
+ test_files:
98
+ - test/test_helper.rb
99
+ - test/test_publisher.rb