apicake 0.1.3 → 0.1.4

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: 5e37316523122c1cc0324208f5de204a9d6c837478dbb8b522410120487a1404
4
- data.tar.gz: a0d5118f54fbd5af3d37d06e106f856c1fa3dc7d85f4ba3ccf56498808ed9f2a
3
+ metadata.gz: 2016b0c4a2652010b263db2d6e6d85804c2cfb23f9c8a8c0d66e55f443e4dee6
4
+ data.tar.gz: 56475f108cc6bb2ad7637005af0f58a73b0bd4cb1587c22f49ec50a61f1aafa3
5
5
  SHA512:
6
- metadata.gz: bda6c3815dcb8c670883c0bf82b55bdcc32ce0461642149727253d8c4d1657c48ba9d7bec94b0a2b979a8030e42c72c6a2c78f02c429d9ff70dadb0509d21133
7
- data.tar.gz: '0258f564a7ff9d17e60cbdaa8b0194f4b115494ddcb6fcf0fa38a9cdf00a1ab661f93c9efc3556de43b84d89c329ed92df28a19b023a2fefb4dec25b0b6937f2'
6
+ metadata.gz: 1345df60ac9a9cba25e27a846b14571c3c84e33fe124d4917ef198f0f8d471f2e59a855d5456b909739e29a1c37791f72a3455f30811ab03f70c338dddef0da4
7
+ data.tar.gz: c491ea7c9e46d9f028ae37723ffc3003226360714cf3d581a1448b54a981fc0392b488c2d28c71ee36abb9d072e34bc8cb3171d7c6f8b2f3d36862ebc9178e9a
data/README.md CHANGED
@@ -2,9 +2,8 @@ API Cake - Build Dynamic API Wrappers
2
2
  ==================================================
3
3
 
4
4
  [![Gem Version](https://badge.fury.io/rb/apicake.svg)](https://badge.fury.io/rb/apicake)
5
- [![Build Status](https://travis-ci.com/DannyBen/apicake.svg?branch=master)](https://travis-ci.com/DannyBen/apicake)
5
+ [![Build Status](https://github.com/DannyBen/apicake/workflows/Test/badge.svg)](https://github.com/DannyBen/apicake/actions?query=workflow%3ATest)
6
6
  [![Maintainability](https://api.codeclimate.com/v1/badges/07bd0f8653914ce703a6/maintainability)](https://codeclimate.com/github/DannyBen/apicake/maintainability)
7
- [![Test Coverage](https://api.codeclimate.com/v1/badges/07bd0f8653914ce703a6/test_coverage)](https://codeclimate.com/github/DannyBen/apicake/test_coverage)
8
7
 
9
8
  ---
10
9
 
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
 
@@ -151,11 +150,11 @@ module APICake
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.3"
3
- end
2
+ VERSION = "0.1.4"
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.3
4
+ version: 0.1.4
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: 2019-01-11 00:00:00.000000000 Z
11
+ date: 2021-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lightly
@@ -53,7 +53,9 @@ files:
53
53
  homepage: https://github.com/DannyBen/apicake
54
54
  licenses:
55
55
  - MIT
56
- metadata: {}
56
+ metadata:
57
+ bug_tracker_uri: https://github.com/DannyBen/apicake/issues
58
+ source_code_uri: https://github.com/DannyBen/apicake
57
59
  post_install_message:
58
60
  rdoc_options: []
59
61
  require_paths:
@@ -62,15 +64,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
62
64
  requirements:
63
65
  - - ">="
64
66
  - !ruby/object:Gem::Version
65
- version: 2.2.2
67
+ version: '2.4'
66
68
  required_rubygems_version: !ruby/object:Gem::Requirement
67
69
  requirements:
68
70
  - - ">="
69
71
  - !ruby/object:Gem::Version
70
72
  version: '0'
71
73
  requirements: []
72
- rubyforge_project:
73
- rubygems_version: 2.7.6
74
+ rubygems_version: 3.2.25
74
75
  signing_key:
75
76
  specification_version: 4
76
77
  summary: API Building Toolkit