bimbly 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c3e11a328ed271b7f1c97eef441d9c7b50c6952e
4
- data.tar.gz: c64b8e7607dab495c1af4417f8659d4e1ad44cc8
3
+ metadata.gz: e7c36f37dd2d247f733bbeb4d380ee12c42b4d37
4
+ data.tar.gz: 7987d33554de4e38667705ceef45e407a1689518
5
5
  SHA512:
6
- metadata.gz: 91700face2b8c4d46599420e760087a616488b661522d4c58e8245f861e196bf97268ee98c1d8bd29f9c2a6ef2f94efad2c29a2d8b55ecc2cc3ce6b88099b731
7
- data.tar.gz: 65c2d30304aa5b3943474623f7429f477ddcd781bbd15e4c6cedea8c4c60bb7d386b7c287abc111864425651c26ade0cc9c0182065574066e3f9d8729f869532
6
+ metadata.gz: ed68f34c77cdfeccb9dc7fd2d6ed89c5f320a40972a8977ae712739852b7af8cf773aa54daaccff099c05c1d346b4b607b86e19abb4cf2bfd0f0908351595fa5
7
+ data.tar.gz: 94d7be01a4f9868eb6b69f7dc3121812aa4c71de076bcbb151890328c3480ace31ee7e52078ea24806202360af0dacbdd39219b61b86e2e48f05d8b0844e09c9
data/lib/bimbly.rb CHANGED
@@ -11,13 +11,17 @@ class Bimbly
11
11
 
12
12
  def initialize(opts = {})
13
13
  # Read in setup files
14
- #@error_codes = YAML.load(File.read("#{File.dirname(__FILE__)}/errors_by_code.yml"))
15
- #@error_names = YAML.load(File.read("#{File.dirname(__FILE__)}/errors_by_name.yml"))
16
- @error_codes = YAML.load(File.read("#{File.dirname(__FILE__)}/error_codes.yml"))
17
- #@obj_sets = YAML.load(File.read("#{File.dirname(__FILE__)}/object_sets.yml"))
18
- @obj_sets = YAML.load(File.read("#{File.dirname(__FILE__)}/object_sets_v2.yml"))
19
- @data_type = YAML.load(File.read("#{File.dirname(__FILE__)}/data_types.yml"))
20
-
14
+ if opts[:version] == "3"
15
+ opts.delete(:version)
16
+ @error_codes = YAML.load(File.read("#{File.dirname(__FILE__)}/error_codes_v3.yml"))
17
+ @obj_sets = YAML.load(File.read("#{File.dirname(__FILE__)}/object_sets_v3.yml"))
18
+ @data_type = YAML.load(File.read("#{File.dirname(__FILE__)}/data_types_v3.yml"))
19
+ else
20
+ @error_codes = YAML.load(File.read("#{File.dirname(__FILE__)}/error_codes_v4.yml"))
21
+ @obj_sets = YAML.load(File.read("#{File.dirname(__FILE__)}/object_sets_v4.yml"))
22
+ @data_type = YAML.load(File.read("#{File.dirname(__FILE__)}/data_types_v4.yml"))
23
+ end
24
+
21
25
  @meth_name = nil
22
26
 
23
27
  @base_url = "NotConnected"
@@ -43,6 +47,13 @@ class Bimbly
43
47
  # Check if url is valid
44
48
  raise ArgumentError, "Invalid URL: #{uri}" unless uri =~ /\A#{URI::regexp}\z/
45
49
 
50
+ # Do some payload stuff to wrap with 'data' and make sure it's usable
51
+ if not payload.nil?
52
+ # payload = payload["data"] if payload.keys.size == 1 and payload.keys.include?("data")
53
+
54
+ payload = { data: payload }
55
+ end
56
+
46
57
  payload = payload.to_json if payload.class == Hash
47
58
 
48
59
  begin
@@ -93,8 +104,6 @@ class Bimbly
93
104
 
94
105
  if @file
95
106
  conn_data = YAML.load(File.read(File.expand_path(@file)))
96
- puts File.expand_path(@file)
97
- puts conn_data
98
107
  conn_data = conn_data[@file_select] if @file_select
99
108
  @array = conn_data["array"]
100
109
  @cert = conn_data["cert"]
@@ -259,9 +268,16 @@ class Bimbly
259
268
  uri = gen_uri(url_suffix: url_suffix,
260
269
  params: opts[:params])
261
270
 
271
+ payload = opts[:payload]
272
+ # Unwrap the payload data if it is json or wrapped in 'data' so we can inspect the attrs
273
+ if not payload.nil?
274
+ payload = JSON.parse(payload) if payload.class == String
275
+ payload = payload["data"] if payload.keys.include?("data")
276
+ end
277
+
262
278
  @uri = uri
263
279
  @verb = hash[:verb]
264
- @payload = opts[:payload]
280
+ @payload = payload
265
281
 
266
282
  if not opts[:params].nil?
267
283
  opts[:params].each { |key, value|
@@ -281,16 +297,16 @@ class Bimbly
281
297
 
282
298
  raise ArgumentError,
283
299
  "Must supply :payload with attributes #{mando_array} on #{method_name}" if
284
- not mando_array.empty? and opts[:payload].nil?
300
+ not mando_array.empty? and payload.nil?
285
301
 
286
302
  mando_array.each { |ele|
287
303
  raise ArgumentError,
288
304
  "\'#{ele}\' is a mandatory attribute in the payload for #{method_name}: Please supply these attributes #{mando_array}" unless
289
- opts[:payload].keys.to_s.include?(ele)
305
+ payload.keys.to_s.include?(ele)
290
306
  }
291
307
 
292
- if not opts[:payload].nil?
293
- opts[:payload].keys.each { |key|
308
+ if not payload.nil?
309
+ payload.keys.each { |key|
294
310
  raise ArgumentError,
295
311
  "The attribute \'#{key}\' is not an available attribute for #{method_name}" unless
296
312
  hash[:request].keys.include?(key.to_s)
File without changes