api_consumer 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +8 -8
  2. data/lib/api_consumer.rb +18 -3
  3. metadata +16 -2
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OTZiMWQyYjk1NDFhZmMzZjU2ZTY3NzYwMjczNjE3MGQ5NWE4ZjZkNQ==
4
+ NzRjZjU5NGY2OWVhYTdjYmY2YTkxYTZhMDJmNzg4Y2VlOGY0ODhmMA==
5
5
  data.tar.gz: !binary |-
6
- YTkyZmFkY2Q4MzhhNzkyNDhjNTEyNTU1MTIzM2E5NjFiYzM5Zjc0Ng==
6
+ MjhlZjlhMjY5MmMxYmE2MzZmMjZlYzkxMTQ0ZjM3MDBmZDI4YzYwOQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZThlM2FhOWRlYzhkMGQ2Yjc5ZWJhZTFlZjJkOWEwMDc0MGY2MGQwZTk0MmZi
10
- MTUzNjIxNjcwZTE4Y2FiYjdiYTdhNTI2YjRlNjc3ZDgxYTQzY2NkNGI1NmIy
11
- NTk3MTRhMWQ5ZTE2OWRiMzAwMDI2MTEyMGM5ZmNiZDMzNzAxMGM=
9
+ YmRjZmIwMzg1NzFkNWVkNzdiNTIwZGFlZjkxOWY0ZGY4M2RiY2RhNWY0N2Zm
10
+ NTlmNmExYWJmNmFiZjY0Njg5M2JiYWY0YzAyNzJmZGFmODExM2FlMGIyNmZm
11
+ MzMxZjM1ODFiMGNlMzAwZWViOTViYjc3N2Y1YzBjOTk5NzAwMTI=
12
12
  data.tar.gz: !binary |-
13
- NTA4MjE3ZjEyZjZjN2I4NjU3ZjcwNjE5ZTM5MmVhODg2ZTIzODdhMTk3NGI2
14
- ZGYzNmZjMmQwYTE3MTU4ZjIzNWUxNmVhNTJhMmVjY2MxYmM0ZTQ1MjZjMWU2
15
- ZTE5NjQ0OTY2MTVjNTM2N2RmMzE1Yzk4OTUwMzIyYTZjMTUwMWM=
13
+ ODdhZWNlMTBmNDk5ZmRmNzM4YjhjODVhOWExN2ExNzZiODA3MzMxMGI3NmRm
14
+ YjRiM2IxNzA5M2Y0YzdkZGQ2NDU2ZTM1YjcyYTNjNDVkNjNkMDdkOWUxOTkz
15
+ ZDc0NGQ1OGQ3ZThhMmQ2ZGZlZWYwOWQxZDdiMzg4MTViZmY5ZjM=
@@ -4,6 +4,7 @@ class APIConsumer
4
4
  require 'uri'
5
5
  require 'json'
6
6
  require 'nokogiri'
7
+ require 'nori'
7
8
  require 'uber_cache'
8
9
  require 'logger'
9
10
 
@@ -93,7 +94,7 @@ class APIConsumer
93
94
  elsif( opts[:method] == :put)
94
95
  Net::HTTP::Put.new(path)
95
96
  else
96
- log.error "BUG - method=>(#{opts[:method]})"
97
+ log.error "Unhandled HTTP method => (#{opts[:method]})"
97
98
  end
98
99
  opts[:headers].each { |k,v| req[k] = v }
99
100
  settings[:headers].each { |k,v| req[k] = v } if settings[:headers]
@@ -112,7 +113,13 @@ class APIConsumer
112
113
  results = error_code(response.code, opts[:errors], results)
113
114
  end
114
115
  results = blk.call(results) if blk
115
- cache.obj_write(opts[:key], results, :ttl => opts[:ttl]) if opts[:key]
116
+ begin
117
+ cache.obj_write(opts[:key], results, :ttl => opts[:ttl]) if opts[:key]
118
+ rescue Exception => exception
119
+ # write error messages to the log file but ignore exceptions in writing data to cache
120
+ log.error exception.message
121
+ log.error exception.backtrace
122
+ end
116
123
  return results
117
124
  elsif( settings[:type] == "rss")
118
125
  rss = Nokogiri::XML(response.body)
@@ -123,7 +130,7 @@ class APIConsumer
123
130
  }
124
131
  }
125
132
  elsif( settings[:type] == "xml")
126
- return Nokogiri::XML(response.body)
133
+ return Nori.new(nori_settings).parse(response.body)
127
134
  end
128
135
  rescue Exception => exception
129
136
  log.error exception.message
@@ -173,6 +180,14 @@ class APIConsumer
173
180
  downcase
174
181
  end
175
182
 
183
+ def nori_settings
184
+ nori_sets = {}
185
+ if settings[:nori_settings].kind_of?(Hash)
186
+ settings[:nori_settings].each{|k, v| nori_sets[k.to_sym] = v}
187
+ end
188
+ return nori_sets
189
+ end
190
+
176
191
  def error_code(code, errors = nil, response = nil)
177
192
  ret_val = {:error => true, :message => (errors && errors[code.to_s] ? errors[code.to_s] : "API error: #{code}" )}
178
193
  ret_val[:response] = response if response
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_consumer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Reister
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-17 00:00:00.000000000 Z
11
+ date: 2015-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: uber_cache
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: nori
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '2.6'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.6'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rspec
43
57
  requirement: !ruby/object:Gem::Requirement