apikit 0.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c84f9b6c87b4164b1ed4a1f84b3190a9c13e4601
4
+ data.tar.gz: 3af85124ca1984034b6aece59a8f1e7a9d291c9b
5
+ SHA512:
6
+ metadata.gz: 0de8aa44d9da0f1028c4033a46f0ae349b19741b245c25c5c99457e7f3acbd5c587814faf9861f06c74d74a26ea317f0d69d84673686c5bda65e5797f7c2f941
7
+ data.tar.gz: 0018b83ca1bcb4ad7e2f9b7a2dd27890c0064dda803c39518c310707e4fdecf7e17196278ef5b76acc5ad1644329dde2452de272f6a8be398f7a7b3b25cbd812
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "https://rubygems.org"
2
+
3
+ group :development, :test do
4
+ gem 'pry'
5
+ end
6
+
7
+ group :test do
8
+ gem 'rspec', '~> 3.1.0'
9
+ gem 'webmock', '~> 1.20.4'
10
+ end
11
+
12
+ gemspec
13
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 niedhui
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Apikit
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'apikit'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install apikit
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/apikit/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ #require "rspec/core/rake_task"
3
+
4
+ #Rspec::Core::RakeTask.new(:spec)
5
+
6
+ #task :default => :spec
7
+
data/apikit.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'apikit/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "apikit"
8
+ spec.version = Apikit::VERSION
9
+ spec.authors = ["niedhui"]
10
+ spec.email = ["niedhui@gmail.com"]
11
+ spec.summary = %q{try to implement an api consumer}
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency 'sawyer', '~> 0.6.0'
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.7"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
@@ -0,0 +1,41 @@
1
+ module Apikit
2
+ class Client
3
+ attr_accessor :api_endpoint
4
+
5
+ def initialize(api_endpoint)
6
+ @api_endpoint = api_endpoint
7
+ end
8
+
9
+ def get(path, options = {})
10
+ request :get, path, options
11
+ end
12
+
13
+ def post(path, options = {})
14
+ request :post, path, options
15
+ end
16
+
17
+ def put(path, options = {})
18
+ request :put, path, options
19
+ end
20
+
21
+ def delete(path, options = {})
22
+ request :delete, path, options
23
+ end
24
+
25
+ def request(method, path, options = {})
26
+ response = agent.call(method, URI::Parser.new.escape(path.to_s), nil, options)
27
+ response.data
28
+ end
29
+
30
+ private
31
+
32
+ def agent
33
+ @agent ||= Sawyer::Agent.new(api_endpoint) do |http|
34
+ http.headers[:content_type] = "application/json"
35
+ end
36
+ end
37
+
38
+ end
39
+ end
40
+
41
+
@@ -0,0 +1,3 @@
1
+ module Apikit
2
+ VERSION = "0.0.1"
3
+ end
data/lib/apikit.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'sawyer'
2
+
3
+ require "apikit/version"
4
+ require 'apikit/client'
5
+
6
+ module Apikit
7
+ end
@@ -0,0 +1,25 @@
1
+
2
+ describe Apikit::Client do
3
+ let(:api_endpoint) { "http://awesome.api"}
4
+ let(:client) { Apikit::Client.new(api_endpoint) }
5
+
6
+ describe ".get" do
7
+ let(:path) { '/ping.json' }
8
+
9
+ it "get parsed result " do
10
+ stub_get = stub_request(:get, api_endpoint + path).to_return(json_response({ok: true}))
11
+ result = client.get(path)
12
+ expect(result.ok).to eq(true)
13
+ end
14
+
15
+ it "get string result (without json response header)" do
16
+ stub_get = stub_request(:get, api_endpoint + path).to_return(body: {ok: true}.to_json)
17
+ result = client.get(path)
18
+ expect(result).to eq("{\"ok\":true}")
19
+ end
20
+
21
+ end
22
+
23
+
24
+
25
+ end
@@ -0,0 +1,85 @@
1
+ require 'apikit'
2
+ require 'webmock/rspec'
3
+ require 'json'
4
+
5
+ RSpec.configure do |config|
6
+ # rspec-expectations config goes here. You can use an alternate
7
+ # assertion/expectation library such as wrong or the stdlib/minitest
8
+ # assertions if you prefer.
9
+ config.expect_with :rspec do |expectations|
10
+ # This option will default to `true` in RSpec 4. It makes the `description`
11
+ # and `failure_message` of custom matchers include text for helper methods
12
+ # defined using `chain`, e.g.:
13
+ # be_bigger_than(2).and_smaller_than(4).description
14
+ # # => "be bigger than 2 and smaller than 4"
15
+ # ...rather than:
16
+ # # => "be bigger than 2"
17
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
18
+ end
19
+
20
+ # rspec-mocks config goes here. You can use an alternate test double
21
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
22
+ config.mock_with :rspec do |mocks|
23
+ # Prevents you from mocking or stubbing a method that does not exist on
24
+ # a real object. This is generally recommended, and will default to
25
+ # `true` in RSpec 4.
26
+ mocks.verify_partial_doubles = true
27
+ end
28
+
29
+ # The settings below are suggested to provide a good initial experience
30
+ # with RSpec, but feel free to customize to your heart's content.
31
+ =begin
32
+ # These two settings work together to allow you to limit a spec run
33
+ # to individual examples or groups you care about by tagging them with
34
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
35
+ # get run.
36
+ config.filter_run :focus
37
+ config.run_all_when_everything_filtered = true
38
+
39
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
40
+ # For more details, see:
41
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
42
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
43
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
44
+ config.disable_monkey_patching!
45
+
46
+ # This setting enables warnings. It's recommended, but in some cases may
47
+ # be too noisy due to issues in dependencies.
48
+ config.warnings = true
49
+
50
+ # Many RSpec users commonly either run the entire suite or an individual
51
+ # file, and it's useful to allow more verbose output when running an
52
+ # individual spec file.
53
+ if config.files_to_run.one?
54
+ # Use the documentation formatter for detailed output,
55
+ # unless a formatter has already been configured
56
+ # (e.g. via a command-line flag).
57
+ config.default_formatter = 'doc'
58
+ end
59
+
60
+ # Print the 10 slowest examples and example groups at the
61
+ # end of the spec run, to help surface which specs are running
62
+ # particularly slow.
63
+ config.profile_examples = 10
64
+
65
+ # Run specs in random order to surface order dependencies. If you find an
66
+ # order dependency and want to debug it, you can fix the order by providing
67
+ # the seed, which is printed after each run.
68
+ # --seed 1234
69
+ config.order = :random
70
+
71
+ # Seed global randomization in this process using the `--seed` CLI option.
72
+ # Setting this allows you to use `--seed` to deterministically reproduce
73
+ # test failures related to randomization by passing the same `--seed` value
74
+ # as the one that triggered the failure.
75
+ e Kernel.srand config.seed
76
+ =end
77
+ end
78
+
79
+ def json_response(hash)
80
+ {
81
+ :body => hash.to_json,
82
+ :headers => {'Content-Type' => 'application/json' }
83
+ }
84
+
85
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: apikit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - niedhui
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sawyer
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.6.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.6.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description:
56
+ email:
57
+ - niedhui@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - apikit.gemspec
69
+ - lib/apikit.rb
70
+ - lib/apikit/client.rb
71
+ - lib/apikit/version.rb
72
+ - spec/apikit/client_spec.rb
73
+ - spec/spec_helper.rb
74
+ homepage: ''
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.2.2
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: try to implement an api consumer
98
+ test_files:
99
+ - spec/apikit/client_spec.rb
100
+ - spec/spec_helper.rb