uboost-client 0.1.8 → 0.1.9

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.
@@ -16,8 +16,13 @@ module UboostClient
16
16
  @debug = options[:debug] || false
17
17
  end
18
18
 
19
- def connection
20
- url = "https://#{@api_credentials[:username]}:#{@api_credentials[:password]}@#{@subdomain}.uboost.com"
19
+ def connection(credentials = nil)
20
+ if credentials
21
+ basic_auth_creds = "#{credentials[:username]}:#{credentials[:password]}"
22
+ else
23
+ basic_auth_creds = "#{@api_credentials[:username]}:#{@api_credentials[:password]}"
24
+ end
25
+ url = "https://#{basic_auth_creds}@#{@subdomain}.uboost.com"
21
26
  Faraday.new(url) do |faraday|
22
27
  faraday.request :url_encoded # form-encode POST params
23
28
  faraday.response :logger if @debug # log requests to STDOUT
@@ -176,12 +181,17 @@ module UboostClient
176
181
  end
177
182
 
178
183
  class Widgets
179
- attr_accessor :url, :client, :session
184
+ attr_accessor :url, :client, :session, :credentials
180
185
 
181
186
  def initialize(client, options)
182
187
  @client = client
183
188
  @url = '/api/widgets'
184
189
  @session = options[:session] || false
190
+ @credentials = options[:credentials] || false
191
+ end
192
+
193
+ def credentials_available?
194
+ @credentials
185
195
  end
186
196
 
187
197
  def session_cache_available?
@@ -203,7 +213,9 @@ module UboostClient
203
213
 
204
214
  def get(url, options)
205
215
  response = nil
206
- if !session_cache_available?
216
+ if credentials_available?
217
+ response = @client.connection(@credentials).get url
218
+ elsif !session_cache_available?
207
219
  response = @client.connection.get url, :sso_token => get_sso_token(options[:account_id])
208
220
  elsif !cached_uboost_id_available?
209
221
  response = @client.connection.get url, :sso_token => get_sso_token(options[:account_id])
@@ -215,24 +227,24 @@ module UboostClient
215
227
  response
216
228
  end
217
229
 
218
- def profile(options)
230
+ def profile(options = Hash.new)
219
231
  options = {:account_id => nil}.merge(options)
220
232
  response = get(@url + '/profile', options)
221
233
  OpenStruct.new(JSON.parse(response.body))
222
234
  end
223
235
 
224
- def my_badges(options)
236
+ def my_badges(options = Hash.new)
225
237
  options = {:account_id => nil, :badge_category_id => 'all'}.merge(options)
226
238
  response = get(@url + '/badges/mine/' + options[:badge_category_id], options)
227
239
  OpenStruct.new(JSON.parse(response.body))
228
240
  end
229
241
 
230
- def list_of_leaderboards(options)
242
+ def list_of_leaderboards(options = Hash.new)
231
243
  response = get(@url + '/leaderboards/', options)
232
244
  OpenStruct.new(JSON.parse(response.body))
233
245
  end
234
246
 
235
- def leaderboard(options)
247
+ def leaderboard(options = Hash.new)
236
248
  options = {:account_id => nil, :leaderboard_id => nil}.merge(options)
237
249
  response = get(@url + '/leaderboards/' + options[:leaderboard_id].to_s, options)
238
250
  OpenStruct.new(JSON.parse(response.body))
@@ -1,3 +1,3 @@
1
1
  class UboostClient
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uboost-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
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-11-06 00:00:00.000000000 Z
12
+ date: 2012-11-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday