gemagent 0.0.1.pre → 0.0.2b
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +17 -31
- data/Rakefile +2 -0
- data/gemagent.gemspec +19 -24
- data/lib/gemagent.rb +5 -0
- data/lib/gemagent/version.rb +3 -0
- data/test/test_helper.rb +0 -0
- metadata +68 -71
- data/CONTRIBUTORS +0 -1
- data/HACKING +0 -8
- data/LICENCE +0 -19
- data/example/example.rb +0 -13
- data/gemagent.rb +0 -8
- data/lib/api_classes.rb +0 -36
- data/lib/api_handler.rb +0 -28
- data/lib/authentication.rb +0 -23
- data/lib/connection.rb +0 -116
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Ryan Stenhouse
|
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
CHANGED
@@ -1,43 +1,29 @@
|
|
1
|
-
Gemagent
|
2
|
-
========
|
1
|
+
# Gemagent
|
3
2
|
|
4
|
-
|
3
|
+
TODO: Write a gem description
|
5
4
|
|
6
|
-
|
7
|
-
-----------
|
5
|
+
## Installation
|
8
6
|
|
9
|
-
|
10
|
-
the FreeAgent Central API.
|
7
|
+
Add this line to your application's Gemfile:
|
11
8
|
|
12
|
-
|
13
|
-
instead to build a 'correct' one. All published API features of the
|
14
|
-
FreeAgent application are implemented.
|
9
|
+
gem 'gemagent'
|
15
10
|
|
16
|
-
|
11
|
+
And then execute:
|
17
12
|
|
18
|
-
|
19
|
-
------------
|
13
|
+
$ bundle
|
20
14
|
|
21
|
-
|
15
|
+
Or install it yourself as:
|
22
16
|
|
23
|
-
$
|
17
|
+
$ gem install gemagent
|
24
18
|
|
25
|
-
|
26
|
-
FreeAgent API.
|
19
|
+
## Usage
|
27
20
|
|
28
|
-
|
29
|
-
---------
|
30
|
-
|
31
|
-
The main purpose of this gem was to allow me to become more familiar
|
32
|
-
with the FreeAgent API and to shake out some cobwebs when it came to
|
33
|
-
my knowledge of Ruby's Standard Library.
|
34
|
-
|
35
|
-
Because of this, some parts (like local data storage) are sub-optimal.
|
36
|
-
|
37
|
-
I have, however, build some abstraction on top of the data storage,
|
38
|
-
HTTP requests and XML parsing to allow for some or all of these
|
39
|
-
components to be replaced at a later date.
|
40
|
-
|
41
|
-
See the documentation online for more information.
|
21
|
+
TODO: Write usage instructions here
|
42
22
|
|
23
|
+
## Contributing
|
43
24
|
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/gemagent.gemspec
CHANGED
@@ -1,25 +1,20 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
GemAgent lets users of FreeAgent Central's online accounting software
|
4
|
-
to interact with the API simply and cleanly by only using functionality
|
5
|
-
provided by Ruby's Standard Library.
|
6
|
-
TXT
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/gemagent/version', __FILE__)
|
7
3
|
|
8
|
-
Gem::Specification.new do |
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Ryan Stenhouse"]
|
6
|
+
gem.email = ["ryan@ryanstenhouse.eu"]
|
7
|
+
gem.summary = %q{GemAgent is a clean and light way to interact with the FreeAgent API.}
|
8
|
+
gem.description = %q{Easily consume FreeAgent's OAuth2 API using simple data structures. Designed to be easily embedded into any application}
|
9
|
+
gem.rubyforge_project = "gemagent"
|
10
|
+
gem.homepage = "http://www.ryanstenhouse.eu/projects/gemagent"
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "gemagent"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Gemagent::VERSION
|
17
|
+
gem.add_dependency "oauth2"
|
18
|
+
gem.add_dependency "jason"
|
19
|
+
gem.add_development_dependency "minitest"
|
20
|
+
end
|
data/lib/gemagent.rb
ADDED
data/test/test_helper.rb
ADDED
File without changes
|
metadata
CHANGED
@@ -1,92 +1,89 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: gemagent
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 1
|
10
|
-
- pre
|
11
|
-
version: 0.0.1.pre
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2b
|
5
|
+
prerelease: 5
|
12
6
|
platform: ruby
|
13
|
-
authors:
|
7
|
+
authors:
|
14
8
|
- Ryan Stenhouse
|
15
9
|
autorequire:
|
16
10
|
bindir: bin
|
17
11
|
cert_chain: []
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
12
|
+
date: 2012-08-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: oauth2
|
16
|
+
requirement: &70220108168200 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70220108168200
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: jason
|
27
|
+
requirement: &70220108167100 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70220108167100
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: minitest
|
38
|
+
requirement: &70220108165840 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70220108165840
|
47
|
+
description: Easily consume FreeAgent's OAuth2 API using simple data structures. Designed
|
48
|
+
to be easily embedded into any application
|
49
|
+
email:
|
50
|
+
- ryan@ryanstenhouse.eu
|
25
51
|
executables: []
|
26
|
-
|
27
52
|
extensions: []
|
28
|
-
|
29
53
|
extra_rdoc_files: []
|
30
|
-
|
31
|
-
|
32
|
-
-
|
33
|
-
-
|
34
|
-
- lib/authentication.rb
|
35
|
-
- lib/connection.rb
|
36
|
-
- ./CONTRIBUTORS
|
37
|
-
- ./example/example.rb
|
38
|
-
- ./gemagent.gemspec
|
39
|
-
- ./gemagent.rb
|
40
|
-
- ./HACKING
|
41
|
-
- ./lib/api_classes.rb
|
42
|
-
- ./lib/api_handler.rb
|
43
|
-
- ./lib/authentication.rb
|
44
|
-
- ./lib/connection.rb
|
45
|
-
- ./LICENCE
|
46
|
-
- ./README.md
|
47
|
-
- gemagent.rb
|
54
|
+
files:
|
55
|
+
- .gitignore
|
56
|
+
- Gemfile
|
57
|
+
- LICENSE
|
48
58
|
- README.md
|
49
|
-
-
|
50
|
-
- LICENCE
|
51
|
-
- CONTRIBUTORS
|
59
|
+
- Rakefile
|
52
60
|
- gemagent.gemspec
|
53
|
-
|
54
|
-
|
61
|
+
- lib/gemagent.rb
|
62
|
+
- lib/gemagent/version.rb
|
63
|
+
- test/test_helper.rb
|
64
|
+
homepage: http://www.ryanstenhouse.eu/projects/gemagent
|
55
65
|
licenses: []
|
56
|
-
|
57
66
|
post_install_message:
|
58
67
|
rdoc_options: []
|
59
|
-
|
60
|
-
require_paths:
|
68
|
+
require_paths:
|
61
69
|
- lib
|
62
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
71
|
none: false
|
64
|
-
requirements:
|
65
|
-
- -
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
|
68
|
-
|
69
|
-
- 1
|
70
|
-
- 8
|
71
|
-
- 4
|
72
|
-
version: 1.8.4
|
73
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
77
|
none: false
|
75
|
-
requirements:
|
76
|
-
- -
|
77
|
-
- !ruby/object:Gem::Version
|
78
|
-
|
79
|
-
segments:
|
80
|
-
- 1
|
81
|
-
- 3
|
82
|
-
- 0
|
83
|
-
version: 1.3.0
|
78
|
+
requirements:
|
79
|
+
- - ! '>'
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 1.3.1
|
84
82
|
requirements: []
|
85
|
-
|
86
|
-
|
87
|
-
rubygems_version: 1.6.1
|
83
|
+
rubyforge_project: gemagent
|
84
|
+
rubygems_version: 1.8.15
|
88
85
|
signing_key:
|
89
86
|
specification_version: 3
|
90
87
|
summary: GemAgent is a clean and light way to interact with the FreeAgent API.
|
91
|
-
test_files:
|
92
|
-
|
88
|
+
test_files:
|
89
|
+
- test/test_helper.rb
|
data/CONTRIBUTORS
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
Ryan Stenhouse <ryan@ryanstenhouse.eu>
|
data/HACKING
DELETED
data/LICENCE
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
Copyright (c) 2011 Ryan Stenhouse and CONTRIBUTORS
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
of this software and associated documentation files (the "Software"), to deal
|
5
|
-
in the Software without restriction, including without limitation the rights
|
6
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
copies of the Software, and to permit persons to whom the Software is
|
8
|
-
furnished to do so, subject to the following conditions:
|
9
|
-
|
10
|
-
The above copyright notice and this permission notice shall be included in
|
11
|
-
all copies or substantial portions of the Software.
|
12
|
-
|
13
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
THE SOFTWARE.
|
data/example/example.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
# GemAgent API Interface
|
2
|
-
# Ryan Stenhouse, 20 January 2011
|
3
|
-
|
4
|
-
# Longhand representation of connecting to the FreeAgent API
|
5
|
-
#
|
6
|
-
ga = GemAgent::NetHttpConnection.new 'you.freeagentcentral.com', GemAgent::HttpBasicAuthentication.new('username','password')
|
7
|
-
ga.verify # => { :user_id => 1, :permission_level => 8, :company_type => UK_LIMITED }
|
8
|
-
|
9
|
-
# Sexy sugary version of the above.
|
10
|
-
#
|
11
|
-
GemAgent::Api.connect 'you.freeagentcentral.com', 'username', 'password' do |api|
|
12
|
-
api.verify # => { :user_id => 1, :permission_level => 8, :company_type => UK_LIMITED }
|
13
|
-
end
|
data/gemagent.rb
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
GEMAGENT_ROOT = File.expand_path(File.dirname(__FILE__))
|
2
|
-
require GEMAGENT_ROOT + '/lib/connection.rb'
|
3
|
-
require GEMAGENT_ROOT + '/lib/authentication.rb'
|
4
|
-
require GEMAGENT_ROOT + '/lib/api_classes.rb'
|
5
|
-
require GEMAGENT_ROOT + '/lib/api_handler.rb'
|
6
|
-
|
7
|
-
module GemAgent
|
8
|
-
end
|
data/lib/api_classes.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
require "rexml/document"
|
2
|
-
|
3
|
-
module GemAgent
|
4
|
-
module Api
|
5
|
-
|
6
|
-
def self.connect(freeagent_url, username, password, connection = GemAgent::NetHttpConnection,
|
7
|
-
authenticator = GemAgent::HttpBasicAuthentication,
|
8
|
-
api_version = GemAgent::ApiHandler)
|
9
|
-
if !block_given?
|
10
|
-
raise "I need to have a block" and return
|
11
|
-
end
|
12
|
-
api = connection.new(freeagent_url, authenticator.new(username, password), api_version)
|
13
|
-
yield api
|
14
|
-
end
|
15
|
-
|
16
|
-
class ApiBase
|
17
|
-
def method
|
18
|
-
'GET'
|
19
|
-
end
|
20
|
-
|
21
|
-
def path
|
22
|
-
end
|
23
|
-
|
24
|
-
def expected_status
|
25
|
-
'200'
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
class Verify < ApiBase
|
31
|
-
def path
|
32
|
-
'/verify'
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
data/lib/api_handler.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/api_classes.rb'
|
2
|
-
module GemAgent
|
3
|
-
class ApiHandler
|
4
|
-
|
5
|
-
def initialize(connection)
|
6
|
-
@connection = connection
|
7
|
-
end
|
8
|
-
|
9
|
-
def verify
|
10
|
-
verify = GemAgent::Api::Verify.new
|
11
|
-
response = @connection.send_request(verify)
|
12
|
-
unless response.has_error?
|
13
|
-
{
|
14
|
-
:company_type => response.headers['company-type'],
|
15
|
-
:user_id => response.headers['user-id'].to_i,
|
16
|
-
:permission_level => response.headers['user-permission-level'].to_i
|
17
|
-
}
|
18
|
-
else
|
19
|
-
{
|
20
|
-
:error => response.headers[:error],
|
21
|
-
:body => response.body,
|
22
|
-
:company_type => 'ERROR'
|
23
|
-
}
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
end
|
data/lib/authentication.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
module GemAgent
|
2
|
-
class ApiAuthentication
|
3
|
-
def authenticate_for(obj)
|
4
|
-
end
|
5
|
-
end
|
6
|
-
|
7
|
-
class HttpBasicAuthentication < ApiAuthentication
|
8
|
-
|
9
|
-
def initialize(username, password)
|
10
|
-
@username = username
|
11
|
-
@password = password
|
12
|
-
end
|
13
|
-
|
14
|
-
def authenticate_for(obj)
|
15
|
-
if obj.respond_to?(:basic_auth)
|
16
|
-
obj.basic_auth @username, @password
|
17
|
-
else
|
18
|
-
raise "Can't do basic authentication with this, I expect a NetHTTP request"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
data/lib/connection.rb
DELETED
@@ -1,116 +0,0 @@
|
|
1
|
-
require 'net/https'
|
2
|
-
require 'uri'
|
3
|
-
|
4
|
-
module GemAgent
|
5
|
-
|
6
|
-
# ConnectionMethod implements the basic interface all child
|
7
|
-
# classes must implement to allow connection to the FreeAgent
|
8
|
-
# API.
|
9
|
-
#
|
10
|
-
class ConnectionMethod
|
11
|
-
|
12
|
-
attr_reader :freeagent_url
|
13
|
-
attr_reader :api
|
14
|
-
attr_reader :authenticator
|
15
|
-
|
16
|
-
@@method_map = {}
|
17
|
-
|
18
|
-
def initialize(freeagent_url, authenticator, api_handler = GemAgent::ApiHandler)
|
19
|
-
@freeagent_url = freeagent_url
|
20
|
-
@authenticator = authenticator
|
21
|
-
@api = api_handler.new(self)
|
22
|
-
end
|
23
|
-
|
24
|
-
def send_request(request)
|
25
|
-
raise "Subclasses of ConnectionMethod must implement their own send_request method"
|
26
|
-
end
|
27
|
-
|
28
|
-
def wrap_response(response)
|
29
|
-
raise "Subclasses of ConnectionMethod must implement their own wrap_response method"
|
30
|
-
end
|
31
|
-
|
32
|
-
# Proxies all undefined method to the API handler
|
33
|
-
# associated with the connection.
|
34
|
-
#
|
35
|
-
def method_missing(method, *args)
|
36
|
-
unless args.empty?
|
37
|
-
@api.send(method, args)
|
38
|
-
else
|
39
|
-
@api.send(method)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
# The ResponseWrapper is used to present a consistant way
|
45
|
-
# for the various API classes to process messages returned
|
46
|
-
# by the API server.
|
47
|
-
#
|
48
|
-
# If you write your own ConnectionMethod subclass, ensure that
|
49
|
-
# your send_request method returns a ResponseWrapper correctly
|
50
|
-
# set with the correct values for headers and body.
|
51
|
-
#
|
52
|
-
class ResponseWrapper
|
53
|
-
attr_reader :headers, :body
|
54
|
-
def initialize(headers, body)
|
55
|
-
@headers = headers
|
56
|
-
@body = body
|
57
|
-
end
|
58
|
-
|
59
|
-
def has_error?
|
60
|
-
!headers[:error].nil?
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
# NetHttpConnection is the default method to connect to the
|
65
|
-
# FreeAgent API. It uses the Standard Ruby library net/http
|
66
|
-
# to create an SSL connection to the FreeAgent server specified
|
67
|
-
# by +@freeagent_url+ and authenticates your request with the
|
68
|
-
# ApiAuthentication subclass you pass thorugh as +authenticator+.
|
69
|
-
#
|
70
|
-
# The last last optional value takes a API Handler class, which
|
71
|
-
# defaults to the standard one which ships with this gem.
|
72
|
-
#
|
73
|
-
class NetHttpConnection < ConnectionMethod
|
74
|
-
|
75
|
-
@@method_map = {
|
76
|
-
'GET' => Net::HTTP::Get,
|
77
|
-
'POST' => Net::HTTP::Post,
|
78
|
-
'PUT' => Net::HTTP::Put,
|
79
|
-
'DELETE' => Net::HTTP::Delete
|
80
|
-
}
|
81
|
-
|
82
|
-
# Sends the +request+ to +@freeagent_url+ over HTTPS. The class
|
83
|
-
# instance variable +@@method_map+ maps each HTTP verb required
|
84
|
-
# to the correct class for instantiation.
|
85
|
-
#
|
86
|
-
def send_request(request)
|
87
|
-
https = Net::HTTP.new(@freeagent_url, Net::HTTP.https_default_port)
|
88
|
-
https.use_ssl = true
|
89
|
-
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
90
|
-
req = @@method_map[request.method].new(request.path)
|
91
|
-
req['content-type'] = 'application/xml'
|
92
|
-
req['accept'] = 'application/xml'
|
93
|
-
authenticator.authenticate_for req
|
94
|
-
resp = nil
|
95
|
-
https.start do |http|
|
96
|
-
resp = http.request(req)
|
97
|
-
end
|
98
|
-
if resp.code == request.expected_status
|
99
|
-
wrap_response(resp)
|
100
|
-
else
|
101
|
-
ResponseWrapper.new({ :error => resp.code, :status => resp.code }, resp.body)
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
# Wraps the response from net/http in a ResponseWrapper object
|
106
|
-
# so the API classes are able to work with it to do their work.
|
107
|
-
#
|
108
|
-
def wrap_response(response)
|
109
|
-
headers = {}
|
110
|
-
response.each_header { |k,v| headers[k] = v }
|
111
|
-
ResponseWrapper.new(headers, response.body)
|
112
|
-
end
|
113
|
-
|
114
|
-
end
|
115
|
-
|
116
|
-
end
|