apicake 0.1.5 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 61152c75df8d4887a4b07dcb947abf7187269648ec316e08d2720731ff99fdc6
4
- data.tar.gz: 9486e4dce9708d24eafda47de4b49f32b6a7b1bf7d29468a28372cf1f7b911d6
3
+ metadata.gz: 99a92916c5b6d98058f53ba677f876d2788ee2a5c3809ff094073c27136b9730
4
+ data.tar.gz: 8728e666564cc4d634c0d8b2eeb77d4ea7654effaf7d4a1f6c88b65907142b6a
5
5
  SHA512:
6
- metadata.gz: c3c63cc09e815e0ff83a25065437b1bef7b3e714dd8da78bb82a3771e3f9868f1bec390028e1815ba3693132ce47ff290d8438500993ba19e2bd5e5b6ad224b5
7
- data.tar.gz: 39665beaf97f8c22b3301b5ad899c8b15f3851aca650e3deb1cb66349114364a7ad30ae39a9292ddbe50fdb17c41c8c9351fb460855119010bfafba9dfd196db
6
+ metadata.gz: 10800e96a2a874a11b2c398f8e0a0bf37e530e7f489c3b3267c66078dbfb9345b762986f07ad0c739ef3f2811efd7135465edad20b037d615101c7687fe96478
7
+ data.tar.gz: e1807403c90bd2dff54f139fe8dd3c48e30aa4a8b73fbb904c69bb23e01c08c3995a89677270b1c558d6da08b320b285abda2ec75af9d1da188e21357954159b
data/README.md CHANGED
@@ -1,21 +1,12 @@
1
- API Cake - Build Dynamic API Wrappers
2
- ==================================================
1
+ # API Cake - Build Dynamic API Wrappers
3
2
 
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)
7
-
8
- ---
3
+ ![repocard](repocard.svg)
9
4
 
10
5
  This gem allows you to easily build rich API wrappers with minimal code.
11
6
 
12
7
  It is HTTParty with a Cake.
13
8
 
14
- ---
15
-
16
-
17
- Install
18
- --------------------------------------------------
9
+ ## Install
19
10
 
20
11
  ```
21
12
  $ gem install apicake
@@ -28,8 +19,7 @@ gem 'apicake'
28
19
  ```
29
20
 
30
21
 
31
- TL;DR
32
- --------------------------------------------------
22
+ ## TL;DR
33
23
 
34
24
  Turn this hypothetical API URL:
35
25
 
@@ -53,8 +43,7 @@ end
53
43
  ```
54
44
 
55
45
 
56
- Features
57
- --------------------------------------------------
46
+ ## Features
58
47
 
59
48
  - Uses HTTParty
60
49
  - Built in caching
@@ -64,8 +53,7 @@ Features
64
53
  - Designed for GET-only APIs (e.g., data services)
65
54
 
66
55
 
67
- Usage
68
- --------------------------------------------------
56
+ ## Usage
69
57
 
70
58
  Create a class and inherit from `APICake::Base`.
71
59
 
@@ -96,8 +84,7 @@ recipes.cakes 'chocolate', layers: 3
96
84
  See the [Examples folder][1] for more examples.
97
85
 
98
86
 
99
- Caching
100
- --------------------------------------------------
87
+ ## Caching
101
88
 
102
89
  APICake uses [Lightly][2] for caching. By default, cached objects are stored
103
90
  in the `./cache` directory for 3600 seconds.
@@ -105,21 +92,21 @@ in the `./cache` directory for 3600 seconds.
105
92
  See the [caching example][3].
106
93
 
107
94
 
108
- Method Reference
109
- --------------------------------------------------
95
+ ## Method Reference
110
96
 
111
97
  For a detailed explanation of the services and methods you get when inheriting
112
98
  from `APICake::Base`, see the [class documentation][4].
113
99
 
114
100
 
115
- Real World Examples
116
- --------------------------------------------------
101
+ ## Real World Examples
117
102
 
118
103
  These gems use APICake:
119
104
 
120
105
  - [Fredric][5] - API wrapper for the FRED database ([go straight to API class][8])
121
106
  - [Intrinio][6] - API wrapper for the Intrinio data service ([go straight to API class][9])
122
107
  - [Quata][7] - API wrapper for the Quandl data service ([go straight to API class][10])
108
+ - [EOD Historical Data][11] - API wrapper for the EOD Historical Data service ([go straight to API class][12])
109
+ - [Nasdaq][13] - API wrapper for the Nasdaq Data Link API ([go straight to API class][14])
123
110
 
124
111
 
125
112
  ---
@@ -133,4 +120,8 @@ These gems use APICake:
133
120
  [7]: https://github.com/DannyBen/quata
134
121
  [8]: https://github.com/DannyBen/fredric/blob/master/lib/fredric/api.rb
135
122
  [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
123
+ [10]: https://github.com/DannyBen/quata/blob/master/lib/quata/api.rb
124
+ [11]: https://github.com/DannyBen/eod
125
+ [12]: https://github.com/DannyBen/eod/blob/master/lib/eod/api.rb
126
+ [13]: https://github.com/dannyben/nasdaq
127
+ [14]: https://github.com/dannyben/nasdaqblob/master/lib/nasdaq/api.rb
data/lib/apicake/base.rb CHANGED
@@ -1,5 +1,6 @@
1
- require "httparty"
2
- require "lightly"
1
+ require 'httparty'
2
+ require 'lightly'
3
+ require 'csv'
3
4
 
4
5
  module APICake
5
6
  # To create your API wrapper, make a class that inherit from this class.
@@ -53,8 +54,13 @@ module APICake
53
54
  #
54
55
  # client.get 'path/optional_sub_path', optional_param: value, optional_param: value
55
56
  #
56
- def method_missing(method_sym, *arguments, &_block)
57
- get "/#{method_sym}", *arguments
57
+ def method_missing(method_sym, *)
58
+ get("/#{method_sym}", *)
59
+ end
60
+
61
+ # Any undefined method call can be handled by this class.
62
+ def respond_to_missing?(*)
63
+ true
58
64
  end
59
65
 
60
66
  # This is the {https://github.com/DannyBen/lightly Lightly} cache object.
@@ -94,7 +100,9 @@ module APICake
94
100
  # p client.last_url
95
101
  # # => "http://some.api.com/v3/some_path?api_key=secret&param=value"
96
102
  #
97
- def default_query; {}; end
103
+ def default_query
104
+ {}
105
+ end
98
106
 
99
107
  # Override this method in order to merge parameters into the HTTParty
100
108
  # get request.
@@ -115,7 +123,9 @@ module APICake
115
123
  #
116
124
  # @see http://www.rubydoc.info/github/jnunemaker/httparty/HTTParty/ClassMethods HTTParty Class Methods documentation
117
125
  #
118
- def default_params; {}; end
126
+ def default_params
127
+ {}
128
+ end
119
129
 
120
130
  # Make a request or get it from cache, and return the parsed response.
121
131
  #
@@ -142,7 +152,7 @@ module APICake
142
152
  key = cache_key path, extra, params
143
153
 
144
154
  @last_payload = cache.get key do
145
- http_get(path, extra, params)
155
+ http_get path, params
146
156
  end
147
157
 
148
158
  @last_url = @last_payload.request.uri.to_s
@@ -178,34 +188,26 @@ module APICake
178
188
  # You can override this method if you wish to provide a different
179
189
  # behavior.
180
190
  #
181
- def get_csv(*args)
182
- payload = get!(*args)
183
-
184
- if payload.response.code != "200"
185
- raise BadResponse, "#{payload.response.code} #{payload.response.msg}"
186
- end
191
+ def get_csv(*)
192
+ payload = get!(*)
193
+ raise BadResponse, "#{payload.response.code} #{payload.response.msg}" if payload.response.code != '200'
187
194
 
188
195
  response = payload.parsed_response
189
-
190
- unless response.is_a? Hash
191
- raise BadResponse, "Cannot parse response"
192
- end
196
+ raise BadResponse, 'Cannot parse response' unless response.is_a? Hash
193
197
 
194
198
  data = csv_node response
195
-
196
199
  header = data.first.keys
197
- result = CSV.generate do |csv|
200
+
201
+ CSV.generate do |csv|
198
202
  csv << header
199
203
  data.each { |row| csv << row.values }
200
204
  end
201
-
202
- result
203
205
  end
204
206
 
205
207
  # Same as {#save}, only use the output of {#get_csv} instead of the
206
208
  # response body.
207
- def save_csv(file, *args)
208
- File.write file, get_csv(*args)
209
+ def save_csv(file, *)
210
+ File.write file, get_csv(*)
209
211
  end
210
212
 
211
213
  # Determins which part of the data is best suited to be displayed
@@ -223,23 +225,23 @@ module APICake
223
225
  arrays.empty? ? [data] : data[arrays.first]
224
226
  end
225
227
 
226
- private
228
+ private
227
229
 
228
230
  # Make a call with HTTParty and return a payload object.
229
- def http_get(path, extra = nil, params = {})
231
+ def http_get(path, params = {})
230
232
  payload = self.class.get path, params
231
233
  APICake::Payload.new payload
232
234
  end
233
235
 
234
236
  # Normalize the three input parameters
235
237
  def normalize(path, extra = nil, params = {})
236
- if extra.is_a?(Hash) and params.empty?
238
+ if extra.is_a?(Hash) && params.empty?
237
239
  params = extra
238
240
  extra = nil
239
241
  end
240
242
 
241
243
  path = "#{path}/#{extra}" if extra
242
- path = "/#{path}" unless path[0] == "/"
244
+ path = "/#{path}" unless path[0] == '/'
243
245
 
244
246
  query = default_query.merge params
245
247
 
@@ -1,3 +1,3 @@
1
1
  module APICake
2
- VERSION = "0.1.5"
2
+ VERSION = '0.2.0'
3
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,43 +1,56 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apicake
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2021-09-30 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: httparty
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '0.20'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '0.20'
13
26
  - !ruby/object:Gem::Dependency
14
27
  name: lightly
15
28
  requirement: !ruby/object:Gem::Requirement
16
29
  requirements:
17
30
  - - "~>"
18
31
  - !ruby/object:Gem::Version
19
- version: '0.1'
32
+ version: '0.3'
20
33
  type: :runtime
21
34
  prerelease: false
22
35
  version_requirements: !ruby/object:Gem::Requirement
23
36
  requirements:
24
37
  - - "~>"
25
38
  - !ruby/object:Gem::Version
26
- version: '0.1'
39
+ version: '0.3'
27
40
  - !ruby/object:Gem::Dependency
28
- name: httparty
41
+ name: csv
29
42
  requirement: !ruby/object:Gem::Requirement
30
43
  requirements:
31
44
  - - "~>"
32
45
  - !ruby/object:Gem::Version
33
- version: '0.14'
46
+ version: '3.3'
34
47
  type: :runtime
35
48
  prerelease: false
36
49
  version_requirements: !ruby/object:Gem::Requirement
37
50
  requirements:
38
51
  - - "~>"
39
52
  - !ruby/object:Gem::Version
40
- version: '0.14'
53
+ version: '3.3'
41
54
  description: Build Dynamic API Wrappers
42
55
  email: db@dannyben.com
43
56
  executables: []
@@ -55,8 +68,9 @@ licenses:
55
68
  - MIT
56
69
  metadata:
57
70
  bug_tracker_uri: https://github.com/DannyBen/apicake/issues
71
+ changelog_uri: https://github.com/DannyBen/apicake/blob/master/CHANGELOG.md
58
72
  source_code_uri: https://github.com/DannyBen/apicake
59
- post_install_message:
73
+ rubygems_mfa_required: 'true'
60
74
  rdoc_options: []
61
75
  require_paths:
62
76
  - lib
@@ -64,15 +78,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
64
78
  requirements:
65
79
  - - ">="
66
80
  - !ruby/object:Gem::Version
67
- version: '2.4'
81
+ version: '3.2'
68
82
  required_rubygems_version: !ruby/object:Gem::Requirement
69
83
  requirements:
70
84
  - - ">="
71
85
  - !ruby/object:Gem::Version
72
86
  version: '0'
73
87
  requirements: []
74
- rubygems_version: 3.2.25
75
- signing_key:
88
+ rubygems_version: 4.0.3
76
89
  specification_version: 4
77
90
  summary: API Building Toolkit
78
91
  test_files: []