http_caller-curb 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +11 -0
- data/Guardfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +7 -0
- data/config.ru +6 -0
- data/http_caller-curb.gemspec +26 -0
- data/lib/http_caller/curb.rb +45 -0
- data/lib/http_caller/curb/version.rb +3 -0
- data/spec/http_caller/curb_spec.rb +91 -0
- data/spec/spec_helper.rb +7 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 05d2419dbfac3d9f7bafaca0a7be1e81bee02083
|
4
|
+
data.tar.gz: 63b76e385fbeb0a0039e17587dc106cea5cfab6c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 097e6d4b053310740851335cff34694f22e7e5ecfd2d7055f4252c9893b80e88e5c535a2807f47fb928e2c74fa17af0a54fe2a7d510db0b27b6a4e1bb24ec442
|
7
|
+
data.tar.gz: 72e47cf37e86106f0e869fa1ad4382c67c780ec4aaf6fbf6af58614882096cb1482c4c047e64258f4478c7164e9b4ca588652b2b0e280c1f69a645b5fc42d719
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Dave Vallance
|
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,29 @@
|
|
1
|
+
# HttpCaller::Curb
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'http_caller-curb'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install http_caller-curb
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/http_caller-curb/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/config.ru
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'http_caller/curb/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "http_caller-curb"
|
8
|
+
spec.version = HttpCaller::CURB_VERSION
|
9
|
+
spec.authors = ["Dave Vallance"]
|
10
|
+
spec.email = ["davevallance@gmail.com"]
|
11
|
+
spec.summary = %q{Used with the simple_api_client gem to allow the use of Curb as the http client.}
|
12
|
+
spec.description = %q{The simple_api_client gem provides Net::Http as a default HttpCaller, this gem adds Curb as an HttpCaller option.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency 'simple_api_client', '> 0.0.1'
|
22
|
+
spec.add_runtime_dependency 'curb'
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "http_caller/curb/version"
|
2
|
+
require 'curb'
|
3
|
+
|
4
|
+
module HttpCaller
|
5
|
+
class Curb
|
6
|
+
|
7
|
+
def response http
|
8
|
+
Response.new(http.response_code, http.body_str)
|
9
|
+
end
|
10
|
+
|
11
|
+
def call opts
|
12
|
+
accept = HttpCaller::APPLICATION_TYPES[opts.fetch(:accept, :json)]
|
13
|
+
content_type = HttpCaller::APPLICATION_TYPES[opts.fetch(:content_type, :json)]
|
14
|
+
|
15
|
+
begin
|
16
|
+
case opts[:method]
|
17
|
+
when :post
|
18
|
+
http = Curl.post(opts[:uri].to_s, opts[:payload]) do |http|
|
19
|
+
http.headers['Content-Type'] = content_type
|
20
|
+
http.headers['Accept'] = accept
|
21
|
+
end
|
22
|
+
response(http)
|
23
|
+
when :get
|
24
|
+
http = Curl.get(opts[:uri].to_s) do |http|
|
25
|
+
http.headers['Accept'] = accept
|
26
|
+
end
|
27
|
+
response(http)
|
28
|
+
when :put
|
29
|
+
http = Curl.put(opts[:uri].to_s, opts[:payload]) do |http|
|
30
|
+
http.headers['Content-Type'] = content_type
|
31
|
+
http.headers['Accept'] = accept
|
32
|
+
end
|
33
|
+
response(http)
|
34
|
+
else
|
35
|
+
raise ArgumentError.new("Unknown call method: #{opts[:method]}")
|
36
|
+
end
|
37
|
+
rescue Curl::Err::ConnectionFailedError
|
38
|
+
raise Errno::ECONNREFUSED
|
39
|
+
rescue Curl::Err::TimeoutError
|
40
|
+
raise Errno::ETIMEDOUT
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
#NOTE: tests require the server to be running. I use the shotgun gem but any rack server should work just run on port 9393 as its hardcoded below. (A sinatra app is created for these tests in config.ru)
|
4
|
+
|
5
|
+
class CurbClient
|
6
|
+
include SimpleApiClient
|
7
|
+
|
8
|
+
# format can be :json or :xml (defaults to :json)
|
9
|
+
def hello_world format
|
10
|
+
call(
|
11
|
+
method: :get,
|
12
|
+
uri: uri('/hello_world'),
|
13
|
+
accept: format
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
# format can be :json or :xml (defaults to :json)
|
18
|
+
def send_data payload, format
|
19
|
+
call(
|
20
|
+
method: :post,
|
21
|
+
uri: uri('/send_data'),
|
22
|
+
payload: payload,
|
23
|
+
accept: format
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
# format can be :json or :xml (defaults to :json)
|
28
|
+
def put payload, format
|
29
|
+
call(
|
30
|
+
method: :put,
|
31
|
+
uri: uri('/put'),
|
32
|
+
payload: payload,
|
33
|
+
accept: format
|
34
|
+
)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe HttpCaller::Curb do
|
39
|
+
|
40
|
+
subject { CurbClient.new('//127.0.0.1:9393/', HttpCaller::Curb.new) }
|
41
|
+
|
42
|
+
it '#call - a get request to /hello_world works when requesting json' do
|
43
|
+
result = subject.hello_world(:json)
|
44
|
+
JSON.parse(result.body)['greeting'].must_equal 'Hello World!'
|
45
|
+
end
|
46
|
+
|
47
|
+
it '#call - a get request to /hello_world works when requesting xml' do
|
48
|
+
result = subject.hello_world :xml
|
49
|
+
xml = Nokogiri::XML(result.body)
|
50
|
+
xml.at_xpath('//greeting').content.must_equal 'Hello World!'
|
51
|
+
end
|
52
|
+
|
53
|
+
it '#call - a post request to /send_data works when sending json' do
|
54
|
+
put_post_json_test
|
55
|
+
end
|
56
|
+
|
57
|
+
it '#call - a post request to /send_data works when sending xml' do
|
58
|
+
put_post_xml_test
|
59
|
+
end
|
60
|
+
|
61
|
+
it '#call - a put request to /put works when sending json' do
|
62
|
+
put_post_json_test
|
63
|
+
end
|
64
|
+
|
65
|
+
it '#call - a put request to /put works when sending xml' do
|
66
|
+
put_post_xml_test
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def put_post_json_test
|
72
|
+
data = {"my_data" => "Is very simple"}
|
73
|
+
result = subject.put data.to_json, :json
|
74
|
+
assert JSON.parse(result.body).must_equal data
|
75
|
+
end
|
76
|
+
|
77
|
+
def put_post_xml_test
|
78
|
+
builder = Nokogiri::XML::Builder.new do |xml|
|
79
|
+
xml.root {
|
80
|
+
xml.data {
|
81
|
+
xml << "My data!"
|
82
|
+
}
|
83
|
+
}
|
84
|
+
end
|
85
|
+
|
86
|
+
result = subject.send_data builder.to_xml, :xml
|
87
|
+
xml = Nokogiri::XML(result.body)
|
88
|
+
xml.at_xpath('//data').content.must_equal 'My data!'
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: http_caller-curb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dave Vallance
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: simple_api_client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.0.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.0.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: curb
|
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.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: The simple_api_client gem provides Net::Http as a default HttpCaller,
|
70
|
+
this gem adds Curb as an HttpCaller option.
|
71
|
+
email:
|
72
|
+
- davevallance@gmail.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- Gemfile
|
79
|
+
- Guardfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- config.ru
|
84
|
+
- http_caller-curb.gemspec
|
85
|
+
- lib/http_caller/curb.rb
|
86
|
+
- lib/http_caller/curb/version.rb
|
87
|
+
- spec/http_caller/curb_spec.rb
|
88
|
+
- spec/spec_helper.rb
|
89
|
+
homepage: ''
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.2.2
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Used with the simple_api_client gem to allow the use of Curb as the http
|
113
|
+
client.
|
114
|
+
test_files:
|
115
|
+
- spec/http_caller/curb_spec.rb
|
116
|
+
- spec/spec_helper.rb
|