rest_api_client 0.1.0.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7f0c78c82058975c3e44495164a19308f64dd7b5
4
+ data.tar.gz: 95ef23b826ef910586cbaeee4792bb018cb09a93
5
+ SHA512:
6
+ metadata.gz: eee2a62564b5fbed3af972dd33fcab89c61e94a06dc928bb68b7960f568ce0b1aaac92374e7ec8bfdc10159cb9b080e2696ac2f8091f4972f4e6f8ec6a96bd10
7
+ data.tar.gz: 68fcab358223851dfa287b55197fd574b7148de5a94de55b3bb94cf31f2816f58def676c3b042f6c54ad12443439477d8216d4072cbf0cdb6ce4135965314690
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.3.0
7
+ before_install: gem install bundler -v 2.0.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in vendor_api_client.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Edgar
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # VendorApiClient
2
+
3
+ A client to subclass from, this gem implements the common HTTP verbs using Faraday to help reduce boiler plates.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'rest_api_client'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install rest_api_client
20
+
21
+ ## Usage
22
+
23
+ Create your own client by subclassing RrestApiClient. Then you can use the HTTP verbs like this:
24
+
25
+ ```
26
+ post(path, body: payload, params: params)
27
+
28
+ ```
29
+
30
+ ## Development
31
+
32
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
33
+
34
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
35
+
36
+ ## Contributing
37
+
38
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ej2015/rest_api_client.
39
+
40
+ ## License
41
+
42
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "vendor_api_client"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,8 @@
1
+ require 'rest_api_client/version'
2
+ require 'rest_api_client/client'
3
+
4
+ module RestApiClient
5
+ def self.client(options = {})
6
+ Client.new(options)
7
+ end
8
+ end
@@ -0,0 +1,26 @@
1
+ module RestApiClient
2
+ class Client
3
+ include RestApiClient::Request
4
+ include RestApiClient::Response
5
+ include RestApiClient::Configuration
6
+
7
+ class << self
8
+ attr_accessor :url
9
+ end
10
+
11
+ attr_accessor :options, :connection
12
+
13
+ def initialize (options = {})
14
+ @options = default_options.merge(options)
15
+ @connection = Faraday.new(@options) do |faraday|
16
+ faraday.request :json
17
+ faraday.request :url_encoded
18
+ faraday.headers[:Accept] = 'application/json'
19
+ faraday.headers['Content-Type'] = 'application/json'
20
+ #faraday.options[:timeout] = 300
21
+ faraday.adapter Faraday.default_adapter
22
+ end
23
+ end
24
+ end
25
+
26
+ end
@@ -0,0 +1,19 @@
1
+ module RestApiClient
2
+ module Configuration
3
+ URL =INSURER_CONFIG["vendor"]["url"].freeze
4
+
5
+ def default_url
6
+ URL
7
+ end
8
+
9
+ def url
10
+ self.class.url || default_url
11
+ end
12
+
13
+ def default_options
14
+ { url: url
15
+ }
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ module RestApiClient
2
+ module Request
3
+
4
+ [:get, :post, :put, :delete].each do |method|
5
+ define_method(method) do |path, body: {}, params: {}, opts: {}|
6
+ request(method, path, body, params, opts)
7
+ end
8
+ end
9
+
10
+ def request(method, path, body, params, opts)
11
+ response = connection.send(method) do | request|
12
+ request.headers = request.headers.merge(opts[:headers]) if opts[:headers].present?
13
+ request.path = URI.encode(path)
14
+ request.params = params if params.present?
15
+ request.body = body if body.present?
16
+ end
17
+ response = Response.create(response)
18
+ rescue Exception => e
19
+ #handle exception
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,24 @@
1
+ module RestApiClient
2
+ module Response
3
+
4
+ def self.create(response)
5
+ status = response.status
6
+ case status
7
+ when 200
8
+ if response.body.present?
9
+ JSON.parse response.body
10
+ else
11
+ response.body
12
+ end
13
+ else
14
+ if response.body.present?
15
+ JSON.parse response.body
16
+ else
17
+ response.body
18
+ end
19
+ end
20
+ rescue JSON::ParserError => e
21
+ { "error" => response.body }
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module RestApiClient
2
+ VERSION = "0.1.0.pre"
3
+ end
@@ -0,0 +1,30 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "rest_api_client/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rest_api_client"
8
+ spec.version = RestApiClient::VERSION
9
+ spec.authors = ["Edgar"]
10
+ spec.email = ["zorro.ej@gmail.com"]
11
+
12
+ spec.summary = %q{A small client to reduce boilerplate code}
13
+ spec.description = %q{Subclass this client and jump into your bizlogic straight away without worrying the HTTP call implementation.}
14
+ spec.homepage = "https://github.com/ej2015/rest_api_client"
15
+ spec.license = "MIT"
16
+
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_development_dependency "bundler", "~> 2.0"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rspec", "~> 3.0"
30
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rest_api_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.pre
5
+ platform: ruby
6
+ authors:
7
+ - Edgar
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-06-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
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: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Subclass this client and jump into your bizlogic straight away without
56
+ worrying the HTTP call implementation.
57
+ email:
58
+ - zorro.ej@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".travis.yml"
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - lib/rest_api_client.rb
73
+ - lib/rest_api_client/client.rb
74
+ - lib/rest_api_client/configuration.rb
75
+ - lib/rest_api_client/request.rb
76
+ - lib/rest_api_client/response.rb
77
+ - lib/rest_api_client/version.rb
78
+ - rest_api_client.gemspec
79
+ homepage: https://github.com/ej2015/rest_api_client
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.3.1
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.6.14
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: A small client to reduce boilerplate code
103
+ test_files: []