api_consumer 0.0.4 → 0.0.5

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 +9 -4
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MjFlZjRhODI3MThlNDJjYmI4ZTU4Y2UxNDk4MWMwNGVhNTNmYjk3OA==
4
+ OTZiMWQyYjk1NDFhZmMzZjU2ZTY3NzYwMjczNjE3MGQ5NWE4ZjZkNQ==
5
5
  data.tar.gz: !binary |-
6
- M2RlZjQ0NjZlYzU3MzU5ZDY5ZDcwYmZmNTA2ODBjNjIzMjEyZjZiYw==
6
+ YTkyZmFkY2Q4MzhhNzkyNDhjNTEyNTU1MTIzM2E5NjFiYzM5Zjc0Ng==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YzQ5M2Y5NzgzNjA0NmNjZTYyOGJiMWJmOWNlYmRjNjAzZjVjYTM4MjU3M2M0
10
- OGUzODU5YTlmMWM2OWQwZmUwN2Q4YjEwMzA4MWNmMmQ3ODI3NTFlZDUxZDhl
11
- YjY5Njg2MjNiZTA0MjAwZTZmMDNkZTUxZmI0ZmFiMmVlYThjNTY=
9
+ ZThlM2FhOWRlYzhkMGQ2Yjc5ZWJhZTFlZjJkOWEwMDc0MGY2MGQwZTk0MmZi
10
+ MTUzNjIxNjcwZTE4Y2FiYjdiYTdhNTI2YjRlNjc3ZDgxYTQzY2NkNGI1NmIy
11
+ NTk3MTRhMWQ5ZTE2OWRiMzAwMDI2MTEyMGM5ZmNiZDMzNzAxMGM=
12
12
  data.tar.gz: !binary |-
13
- NjQxNWIwMmI0NTE5NTIxYWVlZDY4NGZhMTI1NWNkNjNhM2I0MGNhY2YwNjVm
14
- OWRkNDJmODM2Y2Y3OTI3NjEyZDJhNjg0MzgwNDgxYzQ5Nzk5NmRhNDA2ZDEz
15
- ODYzOGNiYmQ0MDYxNWQ2NDU3MGY4ZDM0MzE1YWY5YjMxYTk2OGM=
13
+ NTA4MjE3ZjEyZjZjN2I4NjU3ZjcwNjE5ZTM5MmVhODg2ZTIzODdhMTk3NGI2
14
+ ZGYzNmZjMmQwYTE3MTU4ZjIzNWUxNmVhNTJhMmVjY2MxYmM0ZTQ1MjZjMWU2
15
+ ZTE5NjQ0OTY2MTVjNTM2N2RmMzE1Yzk4OTUwMzIyYTZjMTUwMWM=
data/lib/api_consumer.rb CHANGED
@@ -88,6 +88,10 @@ class APIConsumer
88
88
  Net::HTTP::Get.new(path)
89
89
  elsif( opts[:method] == :post)
90
90
  Net::HTTP::Post.new(path)
91
+ elsif( opts[:method] == :delete)
92
+ Net::HTTP::Delete.new(path)
93
+ elsif( opts[:method] == :put)
94
+ Net::HTTP::Put.new(path)
91
95
  else
92
96
  log.error "BUG - method=>(#{opts[:method]})"
93
97
  end
@@ -105,7 +109,7 @@ class APIConsumer
105
109
  if( settings[:type] == "json")
106
110
  results = JSON.parse(response.body)
107
111
  if ![200, 201].include?(response.code.to_i)
108
- results = error_code(response.code, opts[:errors])
112
+ results = error_code(response.code, opts[:errors], results)
109
113
  end
110
114
  results = blk.call(results) if blk
111
115
  cache.obj_write(opts[:key], results, :ttl => opts[:ttl]) if opts[:key]
@@ -169,9 +173,10 @@ class APIConsumer
169
173
  downcase
170
174
  end
171
175
 
172
- def error_code(code, errors = nil)
173
- return {:error => true, :message => errors[code.to_s]} if errors && errors[code.to_s]
174
- return {:error => true, :message => "API error: #{code}" }
176
+ def error_code(code, errors = nil, response = nil)
177
+ ret_val = {:error => true, :message => (errors && errors[code.to_s] ? errors[code.to_s] : "API error: #{code}" )}
178
+ ret_val[:response] = response if response
179
+ return ret_val
175
180
  end
176
181
  end
177
182
  end
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.4
4
+ version: 0.0.5
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-10-08 00:00:00.000000000 Z
11
+ date: 2014-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: uber_cache