api_consumer 0.0.3 → 0.0.4

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 +10 -4
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NDlmNjk3YWM5NWE3Yjc1ZmY2ZjNlYjdhYjk3NDQ2YWFkODIyNDY0NA==
4
+ MjFlZjRhODI3MThlNDJjYmI4ZTU4Y2UxNDk4MWMwNGVhNTNmYjk3OA==
5
5
  data.tar.gz: !binary |-
6
- MDRjODAxN2E4YmQ3MDQ4OWQ3YTg3ZTQ3NGFjMjU3OWY1Y2Y1NmRkZQ==
6
+ M2RlZjQ0NjZlYzU3MzU5ZDY5ZDcwYmZmNTA2ODBjNjIzMjEyZjZiYw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YzYyYzk0Zjc1ZjQyMzk1NDA0OGZkNjQ2ZGVmMDM4MjY4MzQ4OTAxMDEwYjc5
10
- NGIwM2E2ZTIxM2Y2NmYyOWIzNjU4ZWU3OGEzYTQ0N2VmMDdiNzViZDBmMjJm
11
- YTcwMGFhOTlmNmFkNzk2YjY1NWVlOGZhYjk0MDljZjg2ZmNmZTQ=
9
+ YzQ5M2Y5NzgzNjA0NmNjZTYyOGJiMWJmOWNlYmRjNjAzZjVjYTM4MjU3M2M0
10
+ OGUzODU5YTlmMWM2OWQwZmUwN2Q4YjEwMzA4MWNmMmQ3ODI3NTFlZDUxZDhl
11
+ YjY5Njg2MjNiZTA0MjAwZTZmMDNkZTUxZmI0ZmFiMmVlYThjNTY=
12
12
  data.tar.gz: !binary |-
13
- Njg1NzViN2NlNGQ3YzI1YTZjZjZiYmY5OGNiMGM4OGNmYjVhN2RmMmY2NTc2
14
- MWY0NGY1YzEzYTBjODgxMmViMWNkMjQ3MTBlODdjMGVlNDc4MWQ2NjM3MGI4
15
- NWY5NWE2NmRkOTJmYjQ0M2JlMWI2YjE0NGNkZDFkODlmOTE5MDA=
13
+ NjQxNWIwMmI0NTE5NTIxYWVlZDY4NGZhMTI1NWNkNjNhM2I0MGNhY2YwNjVm
14
+ OWRkNDJmODM2Y2Y3OTI3NjEyZDJhNjg0MzgwNDgxYzQ5Nzk5NmRhNDA2ZDEz
15
+ ODYzOGNiYmQ0MDYxNWQ2NDU3MGY4ZDM0MzE1YWY5YjMxYTk2OGM=
@@ -12,7 +12,7 @@ class APIConsumer
12
12
  def inherited(subclass)
13
13
  configs = YAML.load_file("config/#{snake_case(subclass)}.yml")
14
14
  configs[snake_case(subclass)].each{ |k,v| subclass.set(k.to_sym, v) }
15
- subclass.set_logger(Logger.new(settings[:log_file] || "./log/#{snake_case(subclass)}_api.log"), settings[:log_level])
15
+ subclass.set_logger(Logger.new(subclass.settings[:log_file] || "./log/#{snake_case(subclass)}_api.log"), subclass.settings[:log_level])
16
16
  super
17
17
  end
18
18
 
@@ -73,6 +73,9 @@ class APIConsumer
73
73
  :ttl => 300
74
74
  }
75
75
  def do_request(path, conn, opts = {}, &blk)
76
+ if(opts[:verbose])
77
+ log.debug("Sending request to: #{conn.address}#{':' + conn.port.to_s if conn.port}#{path}")
78
+ end
76
79
  if opts[:key] # cache if key sent
77
80
  read_val = nil
78
81
  return read_val if !opts[:reload] && read_val = cache.obj_read(opts[:key])
@@ -89,14 +92,15 @@ class APIConsumer
89
92
  log.error "BUG - method=>(#{opts[:method]})"
90
93
  end
91
94
  opts[:headers].each { |k,v| req[k] = v }
95
+ settings[:headers].each { |k,v| req[k] = v } if settings[:headers]
92
96
  req.basic_auth settings[:api_user], settings[:api_password] if settings[:api_user] && settings[:api_password]
93
97
  req["connection"] = 'keep-alive'
94
98
  req.body = opts[:body] if opts[:body]
95
99
 
96
100
  response = nil
97
101
  begin
98
- log.warn conn.inspect
99
- log.warn req.inspect
102
+ log.debug "CONN:" + conn.inspect
103
+ log.debug "REQ:" + req.inspect
100
104
  response = conn.request(req)
101
105
  if( settings[:type] == "json")
102
106
  results = JSON.parse(response.body)
@@ -114,6 +118,8 @@ class APIConsumer
114
118
  'description' => i.xpath('description').inner_text
115
119
  }
116
120
  }
121
+ elsif( settings[:type] == "xml")
122
+ return Nokogiri::XML(response.body)
117
123
  end
118
124
  rescue Exception => exception
119
125
  log.error exception.message
@@ -156,7 +162,7 @@ class APIConsumer
156
162
 
157
163
  private
158
164
  def snake_case(camel_cased_word)
159
- camel_cased_word.to_s.gsub(/::/, '/').
165
+ camel_cased_word.to_s.gsub(/::/, '_').
160
166
  gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
161
167
  gsub(/([a-z\d])([A-Z])/,'\1_\2').
162
168
  tr("-", "_").
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.3
4
+ version: 0.0.4
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-06-04 00:00:00.000000000 Z
11
+ date: 2014-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: uber_cache