beebotte 0.1.1 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fd37c393fe2779c46d062e6d63e5857aef14b607
4
- data.tar.gz: 5042564e8a7228df947b303bfe34665d884c4b20
3
+ metadata.gz: 61b32c7b793ae9010f8d2759efb44a5b850852fa
4
+ data.tar.gz: 5f62dc24d1a0421731dfae18311855b57e1b6e21
5
5
  SHA512:
6
- metadata.gz: ee1382b295f31a6440f925e2b2153c17212e29c76d03cba9d594f92c3cdadb7553c6dc5dd831c77e7d77612e3cbe44b414050ad73b70a1f65000cd405ff0e912
7
- data.tar.gz: 6c0de50a52d1ba9764f91267366b07c1c98861edebdb177055134faef10317f95578ea2dde89173abc276ec288d5becba00329b71507ab76c35464f16149d312
6
+ metadata.gz: 8010f6f099a33a21cfc410d86f33122266628eb9c5a7ce780027c174768d91e6528cf22e338eb9e1be758b3d0b76eb568a87d4b7e7a23bd65ee84c0f5a1f8087
7
+ data.tar.gz: f4a105dc940ecf3871ae3402185cc277961730af4ac441c0a25cce1754e6cf6a87c1aaeba148723326a6e58f59305ef66be20fe29d5695db7206529dfec7862d
@@ -12,6 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.summary = "Beebotte REST API connector"
13
13
  spec.description = "A pure ruby implementation of the BBT connector for beebotte's REST api"
14
14
  spec.homepage = "https://github.com/DaKaZ/bbt_ruby"
15
+ spec.license = 'MIT'
15
16
 
16
17
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
18
  f.match(%r{^(test|spec|features)/})
@@ -19,10 +20,9 @@ Gem::Specification.new do |spec|
19
20
  spec.bindir = "exe"
20
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
22
  spec.require_paths = ["lib"]
22
-
23
- spec.add_runtime_dependency 'openssl'
23
+ spec.add_runtime_dependency 'ruby-hmac'
24
24
  spec.add_runtime_dependency 'json'
25
- spec.add_runtime_dependency 'rest-client', '>= 1.8.0'
25
+ spec.add_runtime_dependency 'rest-client', '>= 1.8.0', '< 2.0.0'
26
26
  spec.add_runtime_dependency 'classy_hash'
27
27
  spec.add_runtime_dependency 'mqtt'
28
28
  spec.add_development_dependency "rspec"
@@ -1,7 +1,7 @@
1
- require "beebotte/version"
2
-
3
1
  module Beebotte
4
- require 'openssl'
2
+ require "beebotte/version"
3
+ require 'hmac-sha1'
4
+ require 'base64'
5
5
  require 'json'
6
6
  require 'rest-client'
7
7
  require 'base64'
@@ -83,7 +83,11 @@ module Beebotte
83
83
 
84
84
  body = {data: data}
85
85
  response = post_data("/v1/data/write/#{channel}/#{resource}", body.to_json)
86
- block.call(response.body, response.code) if block
86
+ if block
87
+ block.call(response.body, response.code)
88
+ else
89
+ (response.code >= 200 && response.code < 300) ? true : false
90
+ end
87
91
  end
88
92
 
89
93
  # publish transient information
@@ -93,7 +97,11 @@ module Beebotte
93
97
  raise ArgumentError, 'Data must be a hash object' unless data.is_a?(Hash)
94
98
  body = {data: data}
95
99
  response = post_data("/v1/data/publish/#{channel}/#{resource}", body.to_json)
96
- block.call(response.body, response.code) if block
100
+ if block
101
+ block.call(response.body, response.code)
102
+ else
103
+ (response.code >= 200 && response.code < 300) ? true : false
104
+ end
97
105
  end
98
106
 
99
107
  # Read persisted messages from the specified channel and resource
@@ -110,18 +118,26 @@ module Beebotte
110
118
  rtn = {}
111
119
  uri = "/v1/data/read/#{params[:channel]}/#{params[:resource]}"
112
120
  [:channel, :resource].each {|k| params.delete(k) }
113
- puts "PARAMS: #{params.inspect}"
114
121
  response = get_data(uri, params)
115
122
  rtn = JSON.parse(response.body) if response.code >= 200 && response.code < 300
116
- block.call(rtn, response.code) if block
123
+ if block
124
+ block.call(rtn, response.code)
125
+ else
126
+ (response.code >= 200 && response.code < 300) ? rtn : nil
127
+ end
128
+
117
129
  end
118
130
 
119
131
  def get_connections(user=nil, &block)
120
132
  resource = user.nil? ? [] : {}
121
133
  uri = "/v1/connections" + (resource.is_a?(String) ? "/#{resource}" : '')
122
134
  response = get_data(uri)
123
- resource = JSON.parse(response.body) if response.code >= 200 && response.code < 300
124
- block.call(resource, response.code) if block
135
+ resource = JSON.parse(response.body) if
136
+ if block
137
+ block.call(resource, response.code)
138
+ else
139
+ (response.code >= 200 && response.code < 300) ? resource : nil
140
+ end
125
141
  end
126
142
 
127
143
  def get_conection(user, &block)
@@ -136,7 +152,11 @@ module Beebotte
136
152
  uri = "/v1/channels" + (channel.is_a?(String) ? "/#{channel}" : '')
137
153
  response = get_data(uri)
138
154
  rtn = JSON.parse(response.body) if response.code >= 200 && response.code < 300
139
- block.call(rtn, response.code) if block
155
+ if block
156
+ block.call(rtn, response.code)
157
+ else
158
+ (response.code >= 200 && response.code < 300) ? rtn : nil
159
+ end
140
160
  end
141
161
 
142
162
  def get_channel(channel, &block)
@@ -155,14 +175,22 @@ module Beebotte
155
175
  if response.code >= 200 && response.code < 300
156
176
  get_channel(channel[:name], &block)
157
177
  else
158
- block.call({}, response.code) if block
178
+ if block
179
+ block.call({}, response.code)
180
+ else
181
+ return false
182
+ end
159
183
  end
160
184
  end
161
185
 
162
186
  def del_channel(channel, &block)
163
187
  raise ArgumentError, 'Channel name must be a string' unless channel.is_a?(String)
164
188
  response = del_data("/v1/channels/#{channel}")
165
- block.call(response.body, response.code) if block
189
+ if block
190
+ block.call(response.body, response.code)
191
+ else
192
+ return (response.code >= 200 && response.code < 300) ? true : false
193
+ end
166
194
  end
167
195
 
168
196
  def get_resources(channel, resource='*', &block)
@@ -173,7 +201,11 @@ module Beebotte
173
201
  }
174
202
  response = get_data("/v1/channels/#{channel}/resources", params)
175
203
  rtn = JSON.parse(response.body) if response.code >= 200 && response.code < 300
176
- block.call(rtn, response.code) if block
204
+ if block
205
+ block.call(rtn, response.code)
206
+ else
207
+ return (response.code >= 200 && response.code < 300) ? rtn : nil
208
+ end
177
209
  end
178
210
 
179
211
  def get_resource(channel, resource, &block)
@@ -194,7 +226,12 @@ module Beebotte
194
226
  if response.code >= 200 && response.code < 300
195
227
  get_resource(channel, resource[:name], &block)
196
228
  else
197
- block.call({}, response.code) if block
229
+ if block
230
+ block.call({}, response.code)
231
+ else
232
+ return false
233
+ end
234
+
198
235
  end
199
236
  end
200
237
 
@@ -202,7 +239,11 @@ module Beebotte
202
239
  raise ArgumentError, 'Channel name must be a string' unless channel.is_a?(String)
203
240
  raise ArgumentError, 'Resource name must be a string' unless resource.is_a?(String)
204
241
  response = del_data("/v1/channels/#{channel}/resources/#{resource}")
205
- block.call(response.body, response.code) if block
242
+ if block
243
+ block.call(response.body, response.code)
244
+ else
245
+ return (response.code >= 200 && response.code < 300) ? true : false
246
+ end
206
247
  end
207
248
 
208
249
  private
@@ -218,7 +259,6 @@ module Beebotte
218
259
  signature = get_signature('GET', uri, @headers, @secretKey)
219
260
  @headers["Authorization"] = "#{@apiKey}:#{signature}"
220
261
  url = "#{@protocol}://#{@hostname}:#{@port}#{uri}"
221
- puts "URL: #{url}"
222
262
  response = RestClient.get(url, @headers)
223
263
  end
224
264
 
@@ -227,8 +267,6 @@ module Beebotte
227
267
  signature = get_signature('POST', uri, @headers, @secretKey)
228
268
  @headers["Authorization"] = "#{@apiKey}:#{signature}"
229
269
  url = "#{@protocol}://#{@hostname}:#{@port}#{uri}"
230
- puts "URL: #{url}"
231
- puts "BODY: #{body}"
232
270
  response = RestClient.post(url, body, @headers)
233
271
  end
234
272
 
@@ -237,7 +275,6 @@ module Beebotte
237
275
  signature = get_signature('DELETE', uri, @headers, @secretKey)
238
276
  @headers["Authorization"] = "#{@apiKey}:#{signature}"
239
277
  url = "#{@protocol}://#{@hostname}:#{@port}#{uri}"
240
- puts "URL: #{url}"
241
278
  response = RestClient.delete(url, @headers)
242
279
  end
243
280
 
@@ -247,14 +284,13 @@ module Beebotte
247
284
  raise ArgumentError, 'Invalid method' unless (method == 'GET' || method == 'PUT' || method == 'POST' || method == 'DELETE')
248
285
  raise ArgumentError, 'Invalid path' unless path.is_a?(String) && path.match(/^\//)
249
286
  stringToSign = "#{method}\n#{headers['Content-MD5']}\n#{headers["Content-type"]}\n#{headers["Date"]}\n#{path}"
250
- puts "stiringToSign= \"#{stringToSign}\""
251
287
  signature = sha1_sign(secretKey, stringToSign)
252
288
  end
253
289
 
254
290
  def sha1_sign(secretKey, stringToSign)
255
- digest = OpenSSL::Digest.new('sha1')
256
- hmac = OpenSSL::HMAC.digest(digest, secretKey, stringToSign)
257
- signature = Base64.strict_encode64(hmac)
291
+ hmac = HMAC::SHA1.new(secretKey)
292
+ hmac.update(stringToSign)
293
+ Base64.strict_encode64("#{hmac.digest}")
258
294
  end
259
295
 
260
296
  def get_useragent_string
@@ -1,3 +1,3 @@
1
1
  module Beebotte
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beebotte
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Kazmier
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-03 00:00:00.000000000 Z
11
+ date: 2017-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: openssl
14
+ name: ruby-hmac
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -45,6 +45,9 @@ dependencies:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: 1.8.0
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: 2.0.0
48
51
  type: :runtime
49
52
  prerelease: false
50
53
  version_requirements: !ruby/object:Gem::Requirement
@@ -52,6 +55,9 @@ dependencies:
52
55
  - - ">="
53
56
  - !ruby/object:Gem::Version
54
57
  version: 1.8.0
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: 2.0.0
55
61
  - !ruby/object:Gem::Dependency
56
62
  name: classy_hash
57
63
  requirement: !ruby/object:Gem::Requirement
@@ -211,7 +217,8 @@ files:
211
217
  - lib/beebotte.rb
212
218
  - lib/beebotte/version.rb
213
219
  homepage: https://github.com/DaKaZ/bbt_ruby
214
- licenses: []
220
+ licenses:
221
+ - MIT
215
222
  metadata: {}
216
223
  post_install_message:
217
224
  rdoc_options: []