apicake 0.1.1 → 0.1.5

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
- SHA1:
3
- metadata.gz: c1d09e6b00d7fb1d19163aa2e7a6912dbf571053
4
- data.tar.gz: 48c802fe5b974895e65fd2808b2cdf711087087a
2
+ SHA256:
3
+ metadata.gz: 61152c75df8d4887a4b07dcb947abf7187269648ec316e08d2720731ff99fdc6
4
+ data.tar.gz: 9486e4dce9708d24eafda47de4b49f32b6a7b1bf7d29468a28372cf1f7b911d6
5
5
  SHA512:
6
- metadata.gz: c95806cee75f5e4574ece5ce97bae1c51c345506ec42d7ae5c6b1dd0ea12100269bbce230b725942eb603f7f80028cf40740e453113faa95f6ce314401a25b25
7
- data.tar.gz: d324e21a09236ea45bcd9cbef8e7e702e92b52a519b877534a3c1d5f1ba3c0030fe074f106f2d525ef5b76d69848072d36e7243f00399857fb89e92f5970ce15
6
+ metadata.gz: c3c63cc09e815e0ff83a25065437b1bef7b3e714dd8da78bb82a3771e3f9868f1bec390028e1815ba3693132ce47ff290d8438500993ba19e2bd5e5b6ad224b5
7
+ data.tar.gz: 39665beaf97f8c22b3301b5ad899c8b15f3851aca650e3deb1cb66349114364a7ad30ae39a9292ddbe50fdb17c41c8c9351fb460855119010bfafba9dfd196db
data/README.md CHANGED
@@ -1,11 +1,9 @@
1
1
  API Cake - Build Dynamic API Wrappers
2
2
  ==================================================
3
3
 
4
- [![Gem](https://img.shields.io/gem/v/apicake.svg?style=flat-square)](https://rubygems.org/gems/apicake)
5
- [![Travis](https://img.shields.io/travis/DannyBen/apicake.svg?style=flat-square)](https://travis-ci.org/DannyBen/apicake)
6
- [![Code Climate](https://img.shields.io/codeclimate/github/DannyBen/apicake.svg?style=flat-square)](https://codeclimate.com/github/DannyBen/apicake)
7
- [![Gemnasium](https://img.shields.io/gemnasium/DannyBen/apicake.svg?style=flat-square)](https://gemnasium.com/DannyBen/apicake)
8
-
4
+ [![Gem Version](https://badge.fury.io/rb/apicake.svg)](https://badge.fury.io/rb/apicake)
5
+ [![Build Status](https://github.com/DannyBen/apicake/workflows/Test/badge.svg)](https://github.com/DannyBen/apicake/actions?query=workflow%3ATest)
6
+ [![Maintainability](https://api.codeclimate.com/v1/badges/07bd0f8653914ce703a6/maintainability)](https://codeclimate.com/github/DannyBen/apicake/maintainability)
9
7
 
10
8
  ---
11
9
 
@@ -36,20 +34,21 @@ TL;DR
36
34
  Turn this hypothetical API URL:
37
35
 
38
36
  ```
39
- http://api.recipies.com/cakes?layers=3
37
+ http://api.recipes.com/cakes?layers=3
40
38
  ```
41
39
 
42
40
  To this:
43
41
 
44
42
  ```ruby
45
- Recipies.cakes layers:3
43
+ recipes = Recipes.new
44
+ recipes.cakes layers:3
46
45
  ```
47
46
 
48
47
  Using this code only:
49
48
 
50
49
  ```ruby
51
- class Recipies < APICake::Base
52
- base_url 'api.recipies.com'
50
+ class Recipes < APICake::Base
51
+ base_uri 'api.recipes.com'
53
52
  end
54
53
  ```
55
54
 
@@ -78,20 +77,20 @@ URL.
78
77
  For example:
79
78
 
80
79
  ```ruby
81
- class Recipies << APICake::Base
82
- base_url 'api.recipies.com/v1'
80
+ class Recipes << APICake::Base
81
+ base_uri 'api.recipes.com/v1'
83
82
  end
84
83
 
85
- recipies = Rcipies.new
84
+ recipes = Recipes.new
86
85
 
87
- # This will access http://api.recipies.com/v1/cakes
88
- recipies.cakes
86
+ # This will access http://api.recipes.com/v1/cakes
87
+ recipes.cakes
89
88
 
90
- # This will access http://api.recipies.com/v1/cakes/chocolate
91
- recipies.cakes 'chocolate'
89
+ # This will access http://api.recipes.com/v1/cakes/chocolate
90
+ recipes.cakes 'chocolate'
92
91
 
93
- # This will access http://api.recipies.com/v1/cakes/chocolate?layers=3
94
- recipies.cakes 'chocolate', layers: 3
92
+ # This will access http://api.recipes.com/v1/cakes/chocolate?layers=3
93
+ recipes.cakes 'chocolate', layers: 3
95
94
  ```
96
95
 
97
96
  See the [Examples folder][1] for more examples.
@@ -113,9 +112,25 @@ For a detailed explanation of the services and methods you get when inheriting
113
112
  from `APICake::Base`, see the [class documentation][4].
114
113
 
115
114
 
115
+ Real World Examples
116
+ --------------------------------------------------
117
+
118
+ These gems use APICake:
119
+
120
+ - [Fredric][5] - API wrapper for the FRED database ([go straight to API class][8])
121
+ - [Intrinio][6] - API wrapper for the Intrinio data service ([go straight to API class][9])
122
+ - [Quata][7] - API wrapper for the Quandl data service ([go straight to API class][10])
123
+
124
+
116
125
  ---
117
126
 
118
127
  [1]: https://github.com/DannyBen/apicake/tree/master/examples
119
128
  [2]: https://github.com/DannyBen/lightly
120
129
  [3]: https://github.com/DannyBen/apicake/blob/master/examples/04-caching.rb
121
- [4]: http://www.rubydoc.info/gems/apicake/APICake/Base
130
+ [4]: http://www.rubydoc.info/gems/apicake/0.1.1/APICake/Base
131
+ [5]: https://github.com/DannyBen/fredric
132
+ [6]: https://github.com/DannyBen/intrinio
133
+ [7]: https://github.com/DannyBen/quata
134
+ [8]: https://github.com/DannyBen/fredric/blob/master/lib/fredric/api.rb
135
+ [9]: https://github.com/DannyBen/intrinio/blob/master/lib/intrinio/api.rb
136
+ [10]: https://github.com/DannyBen/quata/blob/master/lib/quata/api.rb
data/lib/apicake/base.rb CHANGED
@@ -1,14 +1,14 @@
1
- require 'httparty'
2
- require 'lightly'
1
+ require "httparty"
2
+ require "lightly"
3
3
 
4
4
  module APICake
5
5
  # To create your API wrapper, make a class that inherit from this class.
6
- #
7
- # This class includes the HTTParty module, and the only requirement,
6
+ #
7
+ # This class includes the HTTParty module, and the only requirement,
8
8
  # is that you call +base_uri+ to define the base URI of the API.
9
9
  #
10
10
  # === Example
11
- #
11
+ #
12
12
  # class Client < APICake::Base
13
13
  # base_uri: 'http://some.api.com/v3'
14
14
  # end
@@ -20,20 +20,19 @@ module APICake
20
20
  # {#get}, {#get!}, {#get_csv} or {#save_csv}
21
21
  #
22
22
  # === Example
23
- #
23
+ #
24
24
  # client = Client.new
25
25
  # client.some_path, param: value
26
26
  # p client.last_payload
27
27
  # # => a Payload object
28
28
  #
29
29
  attr_reader :last_payload
30
-
31
30
 
32
31
  # Holds the last URL that was downloaded by the last call to
33
32
  # {#get}, {#get!}, {#get_csv} or {#save_csv}.
34
33
  #
35
34
  # === Example
36
- #
35
+ #
37
36
  # client = Client.new
38
37
  # client.some_path, param: value
39
38
  # p client.last_url
@@ -42,27 +41,27 @@ module APICake
42
41
  attr_reader :last_url
43
42
 
44
43
  # Any undefined method call will be delegated to the {#get} method.
45
- #
44
+ #
46
45
  # === Example
47
- #
46
+ #
48
47
  # This:
49
48
  #
50
49
  # client = Client.new
51
- # client.path 'optional_sub_path', optional_param: value, optional_param: value
50
+ # client.path 'optional_sub_path', optional_param: value, optional_param: value
52
51
  #
53
52
  # Is equivalent to this:
54
- #
55
- # client.get 'path/optional_sub_path', optional_param: value, optional_param: value
53
+ #
54
+ # client.get 'path/optional_sub_path', optional_param: value, optional_param: value
56
55
  #
57
56
  def method_missing(method_sym, *arguments, &_block)
58
57
  get "/#{method_sym}", *arguments
59
58
  end
60
59
 
61
- # This is the {https://github.com/DannyBen/lightly Lightly} cache object.
60
+ # This is the {https://github.com/DannyBen/lightly Lightly} cache object.
62
61
  # You can access or modify cache settings with this object.
63
62
  #
64
63
  # === Example
65
- #
64
+ #
66
65
  # client = Client.new
67
66
  # client.cache.life = 3600
68
67
  # client.cache.dir = './cache'
@@ -73,42 +72,42 @@ module APICake
73
72
  @cache ||= Lightly.new
74
73
  end
75
74
 
76
- # Override this method in order to merge parameters into the query
75
+ # Override this method in order to merge parameters into the query
77
76
  # string before each call.
78
77
  #
79
78
  # === Example
80
79
  #
81
80
  # class Client < APICake::Base
82
- # base_uri: 'http://some.api.com/v3'
83
- #
81
+ # base_uri: 'http://some.api.com/v3'
82
+ #
84
83
  # def initialize(api_key)
85
84
  # @api_key = api_key
86
85
  # end
87
- #
86
+ #
88
87
  # def default_query
89
88
  # { api_key: @api_key }
90
89
  # end
91
90
  # end
92
- #
91
+ #
93
92
  # client = Client.new 'secret'
94
93
  # client.some_path param: 'value'
95
94
  # p client.last_url
96
95
  # # => "http://some.api.com/v3/some_path?api_key=secret&param=value"
97
96
  #
98
- def default_query; {}; end
97
+ def default_query; {}; end
99
98
 
100
99
  # Override this method in order to merge parameters into the HTTParty
101
- # get request.
100
+ # get request.
102
101
  #
103
102
  # === Eexample
104
103
  #
105
104
  # class Client < APICake::Base
106
- # base_uri: 'http://some.api.com/v3'
107
- #
105
+ # base_uri: 'http://some.api.com/v3'
106
+ #
108
107
  # def initialize(user, pass)
109
108
  # @user, @pass = user, pass
110
109
  # end
111
- #
110
+ #
112
111
  # def default_params
113
112
  # { basic_auth: { username: user, password: pass }
114
113
  # end
@@ -124,7 +123,7 @@ module APICake
124
123
  # value.
125
124
  #
126
125
  # Normally, you should not have the need to use this method, since all
127
- # unhandled method calls are handled by {#method_missing} and are
126
+ # unhandled method calls are handled by {#method_missing} and are
128
127
  # delegated here.
129
128
  #
130
129
  # === Example
@@ -132,13 +131,13 @@ module APICake
132
131
  # client = Client.new
133
132
  # client.get 'path/to/resource', param: value, param: value
134
133
  #
135
- def get(path, extra=nil, params={})
136
- get!(path, extra, params).parsed_response
134
+ def get(path, extra = nil, params = {})
135
+ get!(path.clone, extra.clone, params.clone).parsed_response
137
136
  end
138
137
 
139
- # Make a request or get it from cache, and return the entire {Payload}
138
+ # Make a request or get it from cache, and return the entire {Payload}
140
139
  # object.
141
- def get!(path, extra=nil, params={})
140
+ def get!(path, extra = nil, params = {})
142
141
  path, extra, params = normalize path, extra, params
143
142
  key = cache_key path, extra, params
144
143
 
@@ -146,16 +145,16 @@ module APICake
146
145
  http_get(path, extra, params)
147
146
  end
148
147
 
149
- @last_url = @last_payload.request.last_uri.to_s
148
+ @last_url = @last_payload.request.uri.to_s
150
149
  @last_payload
151
150
  end
152
151
 
153
152
  # A shortcut to just get the constructed URL of the request.
154
- # Note that this call will make the HTTP request (unless it is already
153
+ # Note that this call will make the HTTP request (unless it is already
155
154
  # cached).
156
- #
155
+ #
157
156
  # If you have already made the request, you can use {#last_url} instead.
158
- def url(path, extra=nil, params={})
157
+ def url(path, extra = nil, params = {})
159
158
  get! path, extra, params
160
159
  last_url
161
160
  end
@@ -167,22 +166,22 @@ module APICake
167
166
  # client = Client.new
168
167
  # client.save 'out.json', 'some/to/resource', param: value
169
168
  #
170
- def save(filename, path, params={})
169
+ def save(filename, path, params = {})
171
170
  payload = get! path, nil, params
172
171
  File.write filename, payload.response.body
173
172
  end
174
173
 
175
174
  # This method uses {#get!} to download and parse the content. It then
176
- # makes the best effort to convert the right part of the data to a
175
+ # makes the best effort to convert the right part of the data to a
177
176
  # CSV string.
178
177
  #
179
- # You can override this method if you wish to provide a different
178
+ # You can override this method if you wish to provide a different
180
179
  # behavior.
181
180
  #
182
181
  def get_csv(*args)
183
182
  payload = get!(*args)
184
183
 
185
- if payload.response.code != '200'
184
+ if payload.response.code != "200"
186
185
  raise BadResponse, "#{payload.response.code} #{payload.response.msg}"
187
186
  end
188
187
 
@@ -191,7 +190,7 @@ module APICake
191
190
  unless response.is_a? Hash
192
191
  raise BadResponse, "Cannot parse response"
193
192
  end
194
-
193
+
195
194
  data = csv_node response
196
195
 
197
196
  header = data.first.keys
@@ -203,14 +202,14 @@ module APICake
203
202
  result
204
203
  end
205
204
 
206
- # Same as {#save}, only use the output of {#get_csv} instead of the
205
+ # Same as {#save}, only use the output of {#get_csv} instead of the
207
206
  # response body.
208
207
  def save_csv(file, *args)
209
208
  File.write file, get_csv(*args)
210
209
  end
211
210
 
212
- # Determins which part of the data is best suited to be displayed
213
- # as CSV.
211
+ # Determins which part of the data is best suited to be displayed
212
+ # as CSV.
214
213
  #
215
214
  # - If the response contains one or more arrays, the first array will
216
215
  # be the CSV output
@@ -227,20 +226,20 @@ module APICake
227
226
  private
228
227
 
229
228
  # Make a call with HTTParty and return a payload object.
230
- def http_get(path, extra=nil, params={})
229
+ def http_get(path, extra = nil, params = {})
231
230
  payload = self.class.get path, params
232
231
  APICake::Payload.new payload
233
232
  end
234
233
 
235
234
  # Normalize the three input parameters
236
- def normalize(path, extra=nil, params={})
235
+ def normalize(path, extra = nil, params = {})
237
236
  if extra.is_a?(Hash) and params.empty?
238
237
  params = extra
239
238
  extra = nil
240
239
  end
241
240
 
242
241
  path = "#{path}/#{extra}" if extra
243
- path = "/#{path}" unless path[0] == '/'
242
+ path = "/#{path}" unless path[0] == "/"
244
243
 
245
244
  query = default_query.merge params
246
245
 
@@ -1,3 +1,3 @@
1
1
  module APICake
2
2
  class BadResponse < StandardError; end
3
- end
3
+ end
@@ -3,14 +3,14 @@ module APICake
3
3
  attr_reader :request, :response, :headers, :parsed_response
4
4
 
5
5
  def initialize(response)
6
- @request = response.request
7
- @headers = response.headers
8
- @response = response.response
6
+ @request = response.request
7
+ @headers = response.headers
8
+ @response = response.response
9
9
  @parsed_response = response.parsed_response
10
10
  end
11
11
 
12
12
  def to_h
13
- { request: request, response: response, headers: headers,
13
+ { request: request, response: response, headers: headers,
14
14
  parsed_response: parsed_response }
15
15
  end
16
16
 
@@ -1,3 +1,3 @@
1
1
  module APICake
2
- VERSION = "0.1.1"
3
- end
2
+ VERSION = "0.1.5"
3
+ end
data/lib/apicake.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'apicake/version'
2
- require 'apicake/base'
3
- require 'apicake/payload'
4
- require 'apicake/exceptions'
1
+ require "apicake/version"
2
+ require "apicake/base"
3
+ require "apicake/payload"
4
+ require "apicake/exceptions"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apicake
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-18 00:00:00.000000000 Z
11
+ date: 2021-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lightly
@@ -38,118 +38,6 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0.14'
41
- - !ruby/object:Gem::Dependency
42
- name: runfile
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '0.8'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '0.8'
55
- - !ruby/object:Gem::Dependency
56
- name: runfile-tasks
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '0.4'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '0.4'
69
- - !ruby/object:Gem::Dependency
70
- name: rspec
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '3.5'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '3.5'
83
- - !ruby/object:Gem::Dependency
84
- name: rdoc
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '5.0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '5.0'
97
- - !ruby/object:Gem::Dependency
98
- name: byebug
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '9.0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: '9.0'
111
- - !ruby/object:Gem::Dependency
112
- name: simplecov
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - "~>"
116
- - !ruby/object:Gem::Version
117
- version: '0.13'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - "~>"
123
- - !ruby/object:Gem::Version
124
- version: '0.13'
125
- - !ruby/object:Gem::Dependency
126
- name: require_all
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - "~>"
130
- - !ruby/object:Gem::Version
131
- version: '1.4'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - "~>"
137
- - !ruby/object:Gem::Version
138
- version: '1.4'
139
- - !ruby/object:Gem::Dependency
140
- name: yard
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - "~>"
144
- - !ruby/object:Gem::Version
145
- version: '0.8'
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - "~>"
151
- - !ruby/object:Gem::Version
152
- version: '0.8'
153
41
  description: Build Dynamic API Wrappers
154
42
  email: db@dannyben.com
155
43
  executables: []
@@ -165,7 +53,9 @@ files:
165
53
  homepage: https://github.com/DannyBen/apicake
166
54
  licenses:
167
55
  - MIT
168
- metadata: {}
56
+ metadata:
57
+ bug_tracker_uri: https://github.com/DannyBen/apicake/issues
58
+ source_code_uri: https://github.com/DannyBen/apicake
169
59
  post_install_message:
170
60
  rdoc_options: []
171
61
  require_paths:
@@ -174,15 +64,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
174
64
  requirements:
175
65
  - - ">="
176
66
  - !ruby/object:Gem::Version
177
- version: 2.0.0
67
+ version: '2.4'
178
68
  required_rubygems_version: !ruby/object:Gem::Requirement
179
69
  requirements:
180
70
  - - ">="
181
71
  - !ruby/object:Gem::Version
182
72
  version: '0'
183
73
  requirements: []
184
- rubyforge_project:
185
- rubygems_version: 2.6.6
74
+ rubygems_version: 3.2.25
186
75
  signing_key:
187
76
  specification_version: 4
188
77
  summary: API Building Toolkit