apicake 0.1.4 → 0.1.6

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: 2016b0c4a2652010b263db2d6e6d85804c2cfb23f9c8a8c0d66e55f443e4dee6
4
- data.tar.gz: 56475f108cc6bb2ad7637005af0f58a73b0bd4cb1587c22f49ec50a61f1aafa3
3
+ metadata.gz: 812c64d0f7d4a2004da300a7992177452e9226cc8f160d424da7059f7a9328e5
4
+ data.tar.gz: 4fcb4c15447fffe6cdeb61f971b4592527c68cb6f28f0106e7203832ee25b90e
5
5
  SHA512:
6
- metadata.gz: 1345df60ac9a9cba25e27a846b14571c3c84e33fe124d4917ef198f0f8d471f2e59a855d5456b909739e29a1c37791f72a3455f30811ab03f70c338dddef0da4
7
- data.tar.gz: c491ea7c9e46d9f028ae37723ffc3003226360714cf3d581a1448b54a981fc0392b488c2d28c71ee36abb9d072e34bc8cb3171d7c6f8b2f3d36862ebc9178e9a
6
+ metadata.gz: 7701d7614c3b9f60d448d6c7b9823edd2bd889d25fafc2c289359ef022cfdcb4428de8c2aba2419b014111c860b437c06e6eaca5db6226a378c9959855333d35
7
+ data.tar.gz: c550aae7a16bdbf8156915fb65e3906e457301fdeb4d00862255e88b1fa3fccbaee54421aed025639100707fb70c09e26ed434d797667851d5b0b16c43d799a3
data/README.md CHANGED
@@ -1,5 +1,4 @@
1
- API Cake - Build Dynamic API Wrappers
2
- ==================================================
1
+ # API Cake - Build Dynamic API Wrappers
3
2
 
4
3
  [![Gem Version](https://badge.fury.io/rb/apicake.svg)](https://badge.fury.io/rb/apicake)
5
4
  [![Build Status](https://github.com/DannyBen/apicake/workflows/Test/badge.svg)](https://github.com/DannyBen/apicake/actions?query=workflow%3ATest)
@@ -14,8 +13,7 @@ It is HTTParty with a Cake.
14
13
  ---
15
14
 
16
15
 
17
- Install
18
- --------------------------------------------------
16
+ ## Install
19
17
 
20
18
  ```
21
19
  $ gem install apicake
@@ -28,8 +26,7 @@ gem 'apicake'
28
26
  ```
29
27
 
30
28
 
31
- TL;DR
32
- --------------------------------------------------
29
+ ## TL;DR
33
30
 
34
31
  Turn this hypothetical API URL:
35
32
 
@@ -53,8 +50,7 @@ end
53
50
  ```
54
51
 
55
52
 
56
- Features
57
- --------------------------------------------------
53
+ ## Features
58
54
 
59
55
  - Uses HTTParty
60
56
  - Built in caching
@@ -64,8 +60,7 @@ Features
64
60
  - Designed for GET-only APIs (e.g., data services)
65
61
 
66
62
 
67
- Usage
68
- --------------------------------------------------
63
+ ## Usage
69
64
 
70
65
  Create a class and inherit from `APICake::Base`.
71
66
 
@@ -96,8 +91,7 @@ recipes.cakes 'chocolate', layers: 3
96
91
  See the [Examples folder][1] for more examples.
97
92
 
98
93
 
99
- Caching
100
- --------------------------------------------------
94
+ ## Caching
101
95
 
102
96
  APICake uses [Lightly][2] for caching. By default, cached objects are stored
103
97
  in the `./cache` directory for 3600 seconds.
@@ -105,21 +99,21 @@ in the `./cache` directory for 3600 seconds.
105
99
  See the [caching example][3].
106
100
 
107
101
 
108
- Method Reference
109
- --------------------------------------------------
102
+ ## Method Reference
110
103
 
111
104
  For a detailed explanation of the services and methods you get when inheriting
112
105
  from `APICake::Base`, see the [class documentation][4].
113
106
 
114
107
 
115
- Real World Examples
116
- --------------------------------------------------
108
+ ## Real World Examples
117
109
 
118
110
  These gems use APICake:
119
111
 
120
112
  - [Fredric][5] - API wrapper for the FRED database ([go straight to API class][8])
121
113
  - [Intrinio][6] - API wrapper for the Intrinio data service ([go straight to API class][9])
122
114
  - [Quata][7] - API wrapper for the Quandl data service ([go straight to API class][10])
115
+ - [EOD Historical Data][11] - API wrapper for the EOD Historical Data service ([go straight to API class][12])
116
+ - [Nasdaq][13] - API wrapper for the Nasdaq Data Link API ([go straight to API class][14])
123
117
 
124
118
 
125
119
  ---
@@ -133,4 +127,8 @@ These gems use APICake:
133
127
  [7]: https://github.com/DannyBen/quata
134
128
  [8]: https://github.com/DannyBen/fredric/blob/master/lib/fredric/api.rb
135
129
  [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
130
+ [10]: https://github.com/DannyBen/quata/blob/master/lib/quata/api.rb
131
+ [11]: https://github.com/DannyBen/eod
132
+ [12]: https://github.com/DannyBen/eod/blob/master/lib/eod/api.rb
133
+ [13]: https://github.com/dannyben/nasdaq
134
+ [14]: https://github.com/dannyben/nasdaqblob/master/lib/nasdaq/api.rb
data/lib/apicake/base.rb CHANGED
@@ -1,5 +1,5 @@
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.
@@ -53,8 +53,13 @@ module APICake
53
53
  #
54
54
  # client.get 'path/optional_sub_path', optional_param: value, optional_param: value
55
55
  #
56
- def method_missing(method_sym, *arguments, &_block)
57
- get "/#{method_sym}", *arguments
56
+ def method_missing(method_sym, *args)
57
+ get "/#{method_sym}", *args
58
+ end
59
+
60
+ # Any undefined method call can be handled by this class.
61
+ def respond_to_missing?(*)
62
+ true
58
63
  end
59
64
 
60
65
  # This is the {https://github.com/DannyBen/lightly Lightly} cache object.
@@ -94,7 +99,9 @@ module APICake
94
99
  # p client.last_url
95
100
  # # => "http://some.api.com/v3/some_path?api_key=secret&param=value"
96
101
  #
97
- def default_query; {}; end
102
+ def default_query
103
+ {}
104
+ end
98
105
 
99
106
  # Override this method in order to merge parameters into the HTTParty
100
107
  # get request.
@@ -115,7 +122,9 @@ module APICake
115
122
  #
116
123
  # @see http://www.rubydoc.info/github/jnunemaker/httparty/HTTParty/ClassMethods HTTParty Class Methods documentation
117
124
  #
118
- def default_params; {}; end
125
+ def default_params
126
+ {}
127
+ end
119
128
 
120
129
  # Make a request or get it from cache, and return the parsed response.
121
130
  #
@@ -142,10 +151,10 @@ module APICake
142
151
  key = cache_key path, extra, params
143
152
 
144
153
  @last_payload = cache.get key do
145
- http_get(path, extra, params)
154
+ http_get path, params
146
155
  end
147
156
 
148
- @last_url = @last_payload.request.last_uri.to_s
157
+ @last_url = @last_payload.request.uri.to_s
149
158
  @last_payload
150
159
  end
151
160
 
@@ -180,26 +189,18 @@ module APICake
180
189
  #
181
190
  def get_csv(*args)
182
191
  payload = get!(*args)
183
-
184
- if payload.response.code != "200"
185
- raise BadResponse, "#{payload.response.code} #{payload.response.msg}"
186
- end
192
+ raise BadResponse, "#{payload.response.code} #{payload.response.msg}" if payload.response.code != '200'
187
193
 
188
194
  response = payload.parsed_response
189
-
190
- unless response.is_a? Hash
191
- raise BadResponse, "Cannot parse response"
192
- end
195
+ raise BadResponse, 'Cannot parse response' unless response.is_a? Hash
193
196
 
194
197
  data = csv_node response
195
-
196
198
  header = data.first.keys
197
- result = CSV.generate do |csv|
199
+
200
+ CSV.generate do |csv|
198
201
  csv << header
199
202
  data.each { |row| csv << row.values }
200
203
  end
201
-
202
- result
203
204
  end
204
205
 
205
206
  # Same as {#save}, only use the output of {#get_csv} instead of the
@@ -223,23 +224,23 @@ module APICake
223
224
  arrays.empty? ? [data] : data[arrays.first]
224
225
  end
225
226
 
226
- private
227
+ private
227
228
 
228
229
  # Make a call with HTTParty and return a payload object.
229
- def http_get(path, extra = nil, params = {})
230
+ def http_get(path, params = {})
230
231
  payload = self.class.get path, params
231
232
  APICake::Payload.new payload
232
233
  end
233
234
 
234
235
  # Normalize the three input parameters
235
236
  def normalize(path, extra = nil, params = {})
236
- if extra.is_a?(Hash) and params.empty?
237
+ if extra.is_a?(Hash) && params.empty?
237
238
  params = extra
238
239
  extra = nil
239
240
  end
240
241
 
241
242
  path = "#{path}/#{extra}" if extra
242
- path = "/#{path}" unless path[0] == "/"
243
+ path = "/#{path}" unless path[0] == '/'
243
244
 
244
245
  query = default_query.merge params
245
246
 
@@ -1,3 +1,3 @@
1
1
  module APICake
2
- VERSION = "0.1.4"
2
+ VERSION = '0.1.6'
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,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apicake
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-28 00:00:00.000000000 Z
11
+ date: 2024-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: lightly
14
+ name: httparty
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.1'
19
+ version: '0.20'
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
- version: '0.1'
26
+ version: '0.20'
27
27
  - !ruby/object:Gem::Dependency
28
- name: httparty
28
+ name: lightly
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.14'
33
+ version: '0.3'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.14'
40
+ version: '0.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: base64
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bigdecimal
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: csv
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
41
83
  description: Build Dynamic API Wrappers
42
84
  email: db@dannyben.com
43
85
  executables: []
@@ -56,7 +98,8 @@ licenses:
56
98
  metadata:
57
99
  bug_tracker_uri: https://github.com/DannyBen/apicake/issues
58
100
  source_code_uri: https://github.com/DannyBen/apicake
59
- post_install_message:
101
+ rubygems_mfa_required: 'true'
102
+ post_install_message:
60
103
  rdoc_options: []
61
104
  require_paths:
62
105
  - lib
@@ -64,15 +107,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
64
107
  requirements:
65
108
  - - ">="
66
109
  - !ruby/object:Gem::Version
67
- version: '2.4'
110
+ version: '3.1'
68
111
  required_rubygems_version: !ruby/object:Gem::Requirement
69
112
  requirements:
70
113
  - - ">="
71
114
  - !ruby/object:Gem::Version
72
115
  version: '0'
73
116
  requirements: []
74
- rubygems_version: 3.2.25
75
- signing_key:
117
+ rubygems_version: 3.5.6
118
+ signing_key:
76
119
  specification_version: 4
77
120
  summary: API Building Toolkit
78
121
  test_files: []