apicake 0.1.5 → 0.1.6

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
2
  SHA256:
3
- metadata.gz: 61152c75df8d4887a4b07dcb947abf7187269648ec316e08d2720731ff99fdc6
4
- data.tar.gz: 9486e4dce9708d24eafda47de4b49f32b6a7b1bf7d29468a28372cf1f7b911d6
3
+ metadata.gz: 812c64d0f7d4a2004da300a7992177452e9226cc8f160d424da7059f7a9328e5
4
+ data.tar.gz: 4fcb4c15447fffe6cdeb61f971b4592527c68cb6f28f0106e7203832ee25b90e
5
5
  SHA512:
6
- metadata.gz: c3c63cc09e815e0ff83a25065437b1bef7b3e714dd8da78bb82a3771e3f9868f1bec390028e1815ba3693132ce47ff290d8438500993ba19e2bd5e5b6ad224b5
7
- data.tar.gz: 39665beaf97f8c22b3301b5ad899c8b15f3851aca650e3deb1cb66349114364a7ad30ae39a9292ddbe50fdb17c41c8c9351fb460855119010bfafba9dfd196db
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,7 +151,7 @@ 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
157
  @last_url = @last_payload.request.uri.to_s
@@ -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.5"
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.5
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-30 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: []