sparkmotion 0.0.1.1 → 0.0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -43,8 +43,8 @@ module SparkMotion
43
43
  attr_accessor *DEBUGGER
44
44
 
45
45
  DEFAULT = {
46
- api_key: nil,
47
- api_secret: nil,
46
+ api_key: "YourAPIKey",
47
+ api_secret: "YourAPISecret",
48
48
  api_user: nil,
49
49
  callback: "https://sparkplatform.com/oauth2/callback",
50
50
  endpoint: "https://developers.sparkapi.com", # change to https://api.developers.sparkapi.com for production
@@ -66,15 +66,15 @@ module SparkMotion
66
66
  puts "#{self} initializing..."
67
67
  @@instances << self
68
68
  (VALID_OPTION_KEYS + ACCESS_KEYS).each do |key|
69
- send("#{key.to_s}=", DEFAULT[key])
69
+ send("#{key.to_s}=", opts[key] || DEFAULT[key])
70
70
  end
71
71
  end
72
72
 
73
73
  # Sample Usage:
74
74
  # client = SparkMotion::OAuth2Client.new
75
75
  # client.configure do |config|
76
- # config.api_key = "e8dx727d5padwh6dh1lydapic"
77
- # config.api_secret = "2d6w2rqwisv0o9dxovhp6g98b"
76
+ # config.api_key = "YourAPIKey"
77
+ # config.api_secret = "YourAPISecret"
78
78
  # config.callback = "https://sparkplatform.com/oauth2/callback"
79
79
  # config.auth_endpoint = "https://sparkplatform.com/oauth2"
80
80
  # config.endpoint = 'https://developers.sparkapi.com'
@@ -99,7 +99,7 @@ module SparkMotion
99
99
  end
100
100
  end
101
101
 
102
- return # so that authorization_code will not be printed in output
102
+ return
103
103
  end
104
104
 
105
105
  def authorize &block
@@ -137,21 +137,20 @@ module SparkMotion
137
137
  # https://<spark_endpoint>/<api version>/<spark resource>
138
138
  complete_url = self.endpoint + "/#{version}" + spark_url
139
139
 
140
- headers = {
141
- :"User-Agent" => "MotionSpark RubyMotion Sample App",
142
- :"X-SparkApi-User-Agent" => "MotionSpark RubyMotion Sample App",
143
- :"Authorization" => "OAuth #{self.access_token}"
144
- }
145
-
146
- opts={}
147
- opts.merge!(options)
148
- opts.merge!({:headers => headers})
149
-
150
140
  block ||= lambda { |returned|
151
141
  puts("SparkMotion: default callback")
152
142
  }
153
143
 
154
144
  request = lambda {
145
+ # refresh Authorization header every time `request` is called
146
+ headers = {
147
+ :"User-Agent" => "MotionSpark RubyMotion Sample App",
148
+ :"X-SparkApi-User-Agent" => "MotionSpark RubyMotion Sample App",
149
+ :"Authorization" => "OAuth #{self.access_token}"
150
+ }
151
+ opts={:headers => headers}
152
+ opts.merge!(options)
153
+
155
154
  BW::HTTP.get(complete_url, opts) do |response|
156
155
  puts "SparkMotion: [status code #{response.status_code}] [#{spark_url}]"
157
156
 
@@ -193,8 +192,7 @@ module SparkMotion
193
192
  end
194
193
 
195
194
  def authorized?
196
- # a string is truthy, but this should not return the refresh token
197
- self.refresh_token && self.authorized ? true : false
195
+ self.refresh_token && self.authorized
198
196
  end
199
197
 
200
198
  private
@@ -1,3 +1,3 @@
1
1
  module SparkMotion
2
- VERSION = "0.0.1.1"
3
- end
2
+ VERSION = "0.0.1.2"
3
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sparkmotion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.1
4
+ version: 0.0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: