api_consumer_json 0.0.1 → 0.0.7

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 +4 -4
  2. data/lib/api_consumer.rb +16 -5
  3. metadata +11 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a6134edeadbdf29c8db50d9332336f7783bb145c
4
- data.tar.gz: 9a47d5fc99efcd05adbdbebb6f07bc74b9dfe8e4
3
+ metadata.gz: 9fd0f4a81476afc73d4f6add37fc3d1f50aba1e1
4
+ data.tar.gz: 563e08957e9dbfe74f6a2bc1792fa73d1db3ec24
5
5
  SHA512:
6
- metadata.gz: dfd9b248619b527aee67a10fb04ed25d0d0f4ff97178fc59080ebfdaaf940f62f73b807f6b6108ef25213f7881515668ef9af4800fa03cb803299ac0308b1c0f
7
- data.tar.gz: c5f2381441b8af68279e6d21697cb9ab14c5aac0c4f38d75521e7d52dd1c680eb3cdaac9c707ef08b7141fb6c383b3422982f2fdd879c5b52e13fac2e6f125ae
6
+ metadata.gz: 77512fe3328d8abbc8b89dd1617780366e64aaf0e848f3f9c16a46e686af98a383795f35f6f5446f86747286f505e3036010428222ec04445bec5b0982398d38
7
+ data.tar.gz: 3ab94771e61decda36bc657a11f3c314f850352e33b5e705cf28ca410fbcdf0db79af09a8c8d849440d318f7090b50a898c4b76eec0452909aa2f03ac11c3b5b
data/lib/api_consumer.rb CHANGED
@@ -9,10 +9,14 @@ class APIConsumer
9
9
  class << self
10
10
  @settings = {}
11
11
  def inherited(subclass)
12
- configs = YAML.load_file("config/#{snake_case(subclass)}.yml")
13
- configs[snake_case(subclass)].each{ |k,v| subclass.set(k.to_sym, v) }
14
- subclass.set_logger(Logger.new(subclass.settings[:log_file] || "./log/#{snake_case(subclass)}_api.log"), subclass.settings[:log_level])
15
- super
12
+ if File.exist?("config/#{snake_case(subclass)}.yml")
13
+ configs = YAML.load_file("config/#{snake_case(subclass)}.yml")
14
+ configs[snake_case(subclass)].each{ |k,v| subclass.set(k.to_sym, v) }
15
+ subclass.set_logger(Logger.new(subclass.settings[:log_file] || "./log/#{snake_case(subclass)}_api.log"), subclass.settings[:log_level])
16
+ super
17
+ else
18
+ raise RuntimeError, "Please create config file: 'config/#{snake_case(subclass)}.yml'"
19
+ end
16
20
  end
17
21
 
18
22
  def set_logger(logger, level=nil)
@@ -83,6 +87,7 @@ class APIConsumer
83
87
  opts[:headers] = DEFAULT_REQUEST_OPTS[:headers].merge(opts[:headers] || {})
84
88
  opts[:method] = opts[:method] || DEFAULT_REQUEST_OPTS[:method]
85
89
 
90
+ path = decorate_path( path )
86
91
  req = if( opts[:method] == :get)
87
92
  Net::HTTP::Get.new(path)
88
93
  elsif( opts[:method] == :post)
@@ -97,7 +102,7 @@ class APIConsumer
97
102
  opts[:headers].each { |k,v| req[k] = v }
98
103
  settings[:headers].each { |k,v| req[k] = v } if settings[:headers]
99
104
  req.basic_auth settings[:api_user], settings[:api_password] if settings[:api_user] && settings[:api_password]
100
- req["connection"] = 'keep-alive'
105
+ #req["connection"] = 'keep-alive'
101
106
  req.body = opts[:body] if opts[:body]
102
107
 
103
108
  response = nil
@@ -107,6 +112,8 @@ class APIConsumer
107
112
  response = conn.request(req)
108
113
 
109
114
  results = JSON.parse(response.body)
115
+ accept_codes = [200, 201, 202]
116
+ accept_codes += settings[:accept_codes].map(&:to_i) if settings[:accept_codes]
110
117
  if ![200, 201].include?(response.code.to_i)
111
118
  results = error_code(response.code, opts[:errors], results)
112
119
  end
@@ -164,5 +171,9 @@ class APIConsumer
164
171
  ret_val[:response] = response if response
165
172
  return ret_val
166
173
  end
174
+
175
+ def decorate_path(p)
176
+ p
177
+ end
167
178
  end
168
179
  end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_consumer_json
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Reister
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-28 00:00:00.000000000 Z
11
+ date: 2017-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: uber_cache
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '3.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: fakeweb
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '1.3'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.3'
55
55
  description: Easy to use API consumer - Setup your API connection in a yaml file,
@@ -70,17 +70,17 @@ require_paths:
70
70
  - lib
71
71
  required_ruby_version: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  required_rubygems_version: !ruby/object:Gem::Requirement
77
77
  requirements:
78
- - - '>='
78
+ - - ">="
79
79
  - !ruby/object:Gem::Version
80
80
  version: '0'
81
81
  requirements: []
82
82
  rubyforge_project:
83
- rubygems_version: 2.4.2
83
+ rubygems_version: 2.6.10
84
84
  signing_key:
85
85
  specification_version: 4
86
86
  summary: Consume all the APIs