easy-rest-client 0.1.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: '079169b5a1eba4183e9fe4c87a292dffcf225560'
4
+ data.tar.gz: a299d4303466328dac670f48ce3d62ff54c608eb
5
+ SHA512:
6
+ metadata.gz: e0eb9d918ad73ae8bda0b4833466a9c344d97e80d95fb838705916d14f0d20bc935f94ee0bdd510d7fc3d3cc0e67f5497f2c7d6630f8a7b25113a489febaabff
7
+ data.tar.gz: 440b06c9234e9bb263f61a53839f1aa37369880a2a3598cc73f164f6b21ce6fd53d3f9eca2a581169283f5ee9256294b497880ac97a100868b680b733481005f
@@ -0,0 +1,11 @@
1
+ /.bundle
2
+ /_yardoc
3
+ /coverage
4
+ /doc
5
+ /pkg
6
+ /spec/reports
7
+ /tmp
8
+
9
+ .yardoc
10
+ Gemfile.lock
11
+ .rubocop-http*
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --require spec_helper
2
+ --color
3
+ --format Fuubar
@@ -0,0 +1,2 @@
1
+ inherit_from:
2
+ - https://raw.githubusercontent.com/jeromedalbert/linting-rules/master/rules/.rubocop.yml
@@ -0,0 +1 @@
1
+ 2.4.2
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Jerome Dalbert
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,24 @@
1
+ # EasyRestClient
2
+
3
+ Easy Rest Client is a tiny wrapper around the popular
4
+ [rest-client](https://github.com/rest-client/rest-client)
5
+ gem.
6
+
7
+ It just wraps JSON responses so that you can easily do `response.a.b.c` instead of `response['a']['b']['c']`.
8
+
9
+ Useful when you want to quickly consume an API that does not provide a dedicated library, but still want the comfort of the object dot notation.
10
+
11
+ ## Installation
12
+
13
+ gem install easy-rest-client
14
+
15
+ ## Usage
16
+
17
+ ```ruby
18
+ response = EasyRestClient.get 'http://some-api.com/coconuts/1'
19
+ response.weight_in_pounds #=> 3.2
20
+ ```
21
+
22
+ ## Contributing
23
+
24
+ Bug reports and pull requests are welcome.
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec) do |t|
5
+ t.verbose = false
6
+ end
7
+
8
+ task default: :spec
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'easy-rest-client'
5
+ require 'pry'
6
+
7
+ Pry.start
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pathname'
4
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
5
+ Pathname.new(__FILE__).realpath)
6
+
7
+ require 'rubygems'
8
+ require 'bundler/setup'
9
+
10
+ load Gem.bin_path('rspec-core', 'rspec')
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
@@ -0,0 +1,33 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = 'easy-rest-client'
6
+ spec.version = '0.1.1'
7
+ spec.authors = ['Jerome Dalbert']
8
+ spec.email = ['jerome.dalbert@gmail.com']
9
+
10
+ spec.summary = 'Easily consume rest-client responses by using the dot notation.'
11
+ spec.summary = <<~EOS
12
+ It just wraps JSON responses so that you can easily do response.a.b.c
13
+ instead of response['a']['b']['c'].
14
+ EOS
15
+ spec.homepage = 'https://github.com/jeromedalbert/easy-rest-client'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f =~ %r{^spec/} }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'rest-client', '~> 2.0'
22
+ spec.add_dependency 'hashie'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.15'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'pry'
27
+ spec.add_development_dependency 'awesome_print'
28
+ spec.add_development_dependency 'rspec'
29
+ spec.add_development_dependency 'rspec-its'
30
+ spec.add_development_dependency 'fuubar'
31
+ spec.add_development_dependency 'webmock'
32
+ spec.add_development_dependency 'rubocop', '~> 0.50.0'
33
+ end
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + '/easy_rest_client'
@@ -0,0 +1,44 @@
1
+ require 'rest-client'
2
+ require 'json'
3
+ require 'hashie'
4
+
5
+ class EasyRestClient
6
+
7
+ class << self
8
+ def get(*args); new.send_request(:get, *args); end
9
+ def post(*args); new.send_request(:post, *args); end
10
+ def put(*args); new.send_request(:put, *args); end
11
+ def delete(*args); new.send_request(:delete, *args); end
12
+ def execute(*args); new.send_request(:execute, *args); end
13
+ end
14
+
15
+ def send_request(method_name, *args)
16
+ klass = method_name == :execute ? ::RestClient::Request : ::RestClient
17
+
18
+ response = klass.send(method_name, *args)
19
+
20
+ parse(response)
21
+ end
22
+
23
+ private
24
+
25
+ def parse(response)
26
+ if response.headers[:content_type] !~ %r(application/json)
27
+ return response.body
28
+ end
29
+
30
+ parsed_body = JSON.parse(response.body)
31
+ convert_to_object(parsed_body)
32
+ end
33
+
34
+ def convert_to_object(element)
35
+ if element.is_a?(Hash)
36
+ Hashie::Mash.new(element)
37
+ elsif element.is_a?(Array)
38
+ element.map { |sub_element| convert_to_object(sub_element) }
39
+ else
40
+ element
41
+ end
42
+ end
43
+
44
+ end
metadata ADDED
@@ -0,0 +1,213 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: easy-rest-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Jerome Dalbert
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-10-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: hashie
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.15'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.15'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: awesome_print
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec-its
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: fuubar
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: webmock
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: 0.50.0
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: 0.50.0
167
+ description:
168
+ email:
169
+ - jerome.dalbert@gmail.com
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - ".gitignore"
175
+ - ".rspec"
176
+ - ".rubocop.yml"
177
+ - ".ruby-version"
178
+ - Gemfile
179
+ - LICENSE
180
+ - README.md
181
+ - Rakefile
182
+ - bin/console
183
+ - bin/rspec
184
+ - bin/setup
185
+ - easy-rest-client.gemspec
186
+ - lib/easy-rest-client.rb
187
+ - lib/easy_rest_client.rb
188
+ homepage: https://github.com/jeromedalbert/easy-rest-client
189
+ licenses:
190
+ - MIT
191
+ metadata: {}
192
+ post_install_message:
193
+ rdoc_options: []
194
+ require_paths:
195
+ - lib
196
+ required_ruby_version: !ruby/object:Gem::Requirement
197
+ requirements:
198
+ - - ">="
199
+ - !ruby/object:Gem::Version
200
+ version: '0'
201
+ required_rubygems_version: !ruby/object:Gem::Requirement
202
+ requirements:
203
+ - - ">="
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
206
+ requirements: []
207
+ rubyforge_project:
208
+ rubygems_version: 2.6.13
209
+ signing_key:
210
+ specification_version: 4
211
+ summary: It just wraps JSON responses so that you can easily do response.a.b.c instead
212
+ of response['a']['b']['c'].
213
+ test_files: []