patronage 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/Rakefile +64 -0
- data/VERSION +1 -0
- data/features/patronage.feature +9 -0
- data/features/step_definitions/patronage_steps.rb +0 -0
- data/features/support/env.rb +4 -0
- data/lib/patronage.rb +8 -0
- data/lib/patronage/api.rb +25 -0
- data/lib/patronage/response.rb +34 -0
- data/lib/patronage/service.rb +23 -0
- data/patronage.gemspec +69 -0
- data/spec/patronage_spec.rb +7 -0
- data/spec/spec_helper.rb +9 -0
- metadata +20 -5
data/.document
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
def version
|
5
|
+
if File.exist?('VERSION')
|
6
|
+
File.read('VERSION')
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
begin
|
11
|
+
require 'jeweler'
|
12
|
+
Jeweler::Tasks.new do |gem|
|
13
|
+
gem.name = "patronage"
|
14
|
+
gem.summary = %Q{Generic and simple webservice client library built on top of Patron, which uses libcurl}
|
15
|
+
gem.description = %Q{Generic and simple webservice client library built on top of Patron, which uses libcurl}
|
16
|
+
gem.email = "divoxx@gmail.com"
|
17
|
+
gem.homepage = "http://github.com/divoxx/patronage"
|
18
|
+
gem.authors = ["Rodrigo Kochenburger"]
|
19
|
+
gem.version = version
|
20
|
+
|
21
|
+
gem.add_dependency 'addressable', '>= 2.1.0'
|
22
|
+
gem.add_dependency 'patron', '>= 0.4.2'
|
23
|
+
gem.add_development_dependency "rspec"
|
24
|
+
gem.add_development_dependency "cucumber"
|
25
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
26
|
+
end
|
27
|
+
rescue LoadError
|
28
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
29
|
+
end
|
30
|
+
|
31
|
+
require 'spec/rake/spectask'
|
32
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
33
|
+
spec.libs << 'lib' << 'spec'
|
34
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
35
|
+
end
|
36
|
+
|
37
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
38
|
+
spec.libs << 'lib' << 'spec'
|
39
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
40
|
+
spec.rcov = true
|
41
|
+
end
|
42
|
+
|
43
|
+
task :spec => :check_dependencies
|
44
|
+
|
45
|
+
begin
|
46
|
+
require 'cucumber/rake/task'
|
47
|
+
Cucumber::Rake::Task.new(:features)
|
48
|
+
|
49
|
+
task :features => :check_dependencies
|
50
|
+
rescue LoadError
|
51
|
+
task :features do
|
52
|
+
abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
task :default => :spec
|
57
|
+
|
58
|
+
require 'rake/rdoctask'
|
59
|
+
Rake::RDocTask.new do |rdoc|
|
60
|
+
rdoc.rdoc_dir = 'rdoc'
|
61
|
+
rdoc.title = "patronage #{version}"
|
62
|
+
rdoc.rdoc_files.include('README*')
|
63
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
64
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.7
|
File without changes
|
data/lib/patronage.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module Patronage
|
2
|
+
class API
|
3
|
+
def initialize(base_url, options = {})
|
4
|
+
@session = ::Patron::Session.new
|
5
|
+
@session.base_url = base_url
|
6
|
+
@default_params = options.delete(:params) || {}
|
7
|
+
|
8
|
+
options.each do |key, value|
|
9
|
+
if @session.public_methods.include?("#{key}=")
|
10
|
+
send("#{key}=", value)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def get(url, headers = {})
|
16
|
+
url = ::Addressable::URI.parse(url)
|
17
|
+
url.query_values = url.query_values.merge(@default_params)
|
18
|
+
@session.get(url.to_s, headers)
|
19
|
+
end
|
20
|
+
|
21
|
+
def service(service_name, opts = {})
|
22
|
+
Service.new(self, service_name, opts)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Patronage
|
2
|
+
class Response
|
3
|
+
Parsers = {
|
4
|
+
/^application\/xml/ => lambda { |body| Hash.from_xml(body) },
|
5
|
+
/^text\/xml/ => lambda { |body| Hash.from_xml(body) },
|
6
|
+
}
|
7
|
+
|
8
|
+
def initialize(response)
|
9
|
+
@response = response
|
10
|
+
end
|
11
|
+
|
12
|
+
def method_missing(meth_name, *args)
|
13
|
+
if @response.public_methods.include?(meth_name.to_s)
|
14
|
+
@response.send(meth_name, *args)
|
15
|
+
else
|
16
|
+
super
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def data
|
21
|
+
unless @data
|
22
|
+
mime_type = @response.headers["Content-Type"] || @response.headers["Content-type"] || @response.headers["content-Type"]
|
23
|
+
parser = Parsers.keys.find { |matcher| matcher === mime_type }
|
24
|
+
|
25
|
+
if parser
|
26
|
+
@data = Parsers[parser].call(@response.body)
|
27
|
+
else
|
28
|
+
raise ArgumentError, "unknown parser for #{mime_type}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
@data
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Patronage
|
2
|
+
class Service
|
3
|
+
attr_reader :name
|
4
|
+
|
5
|
+
def initialize(api, name, opts = {})
|
6
|
+
@api = api
|
7
|
+
@name = name.to_s
|
8
|
+
@opts = opts
|
9
|
+
end
|
10
|
+
|
11
|
+
def service_location
|
12
|
+
location = "/#{name}"
|
13
|
+
location << ".#{@opts[:format]}" if @opts[:format]
|
14
|
+
location
|
15
|
+
end
|
16
|
+
|
17
|
+
def get(params)
|
18
|
+
uri = Addressable::URI.parse(service_location)
|
19
|
+
uri.query_values = params
|
20
|
+
Response.new(@api.get(uri.to_s))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/patronage.gemspec
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{patronage}
|
8
|
+
s.version = "0.0.7"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Rodrigo Kochenburger"]
|
12
|
+
s.date = %q{2010-02-18}
|
13
|
+
s.description = %q{Generic and simple webservice client library built on top of Patron, which uses libcurl}
|
14
|
+
s.email = %q{divoxx@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"features/patronage.feature",
|
27
|
+
"features/step_definitions/patronage_steps.rb",
|
28
|
+
"features/support/env.rb",
|
29
|
+
"lib/patronage.rb",
|
30
|
+
"lib/patronage/api.rb",
|
31
|
+
"lib/patronage/response.rb",
|
32
|
+
"lib/patronage/service.rb",
|
33
|
+
"patronage.gemspec",
|
34
|
+
"spec/patronage_spec.rb",
|
35
|
+
"spec/spec_helper.rb"
|
36
|
+
]
|
37
|
+
s.homepage = %q{http://github.com/divoxx/patronage}
|
38
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
39
|
+
s.require_paths = ["lib"]
|
40
|
+
s.rubygems_version = %q{1.3.5}
|
41
|
+
s.summary = %q{Generic and simple webservice client library built on top of Patron, which uses libcurl}
|
42
|
+
s.test_files = [
|
43
|
+
"spec/patronage_spec.rb",
|
44
|
+
"spec/spec_helper.rb"
|
45
|
+
]
|
46
|
+
|
47
|
+
if s.respond_to? :specification_version then
|
48
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
49
|
+
s.specification_version = 3
|
50
|
+
|
51
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
52
|
+
s.add_runtime_dependency(%q<addressable>, [">= 2.1.0"])
|
53
|
+
s.add_runtime_dependency(%q<patron>, [">= 0.4.2"])
|
54
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
55
|
+
s.add_development_dependency(%q<cucumber>, [">= 0"])
|
56
|
+
else
|
57
|
+
s.add_dependency(%q<addressable>, [">= 2.1.0"])
|
58
|
+
s.add_dependency(%q<patron>, [">= 0.4.2"])
|
59
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
60
|
+
s.add_dependency(%q<cucumber>, [">= 0"])
|
61
|
+
end
|
62
|
+
else
|
63
|
+
s.add_dependency(%q<addressable>, [">= 2.1.0"])
|
64
|
+
s.add_dependency(%q<patron>, [">= 0.4.2"])
|
65
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
66
|
+
s.add_dependency(%q<cucumber>, [">= 0"])
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: patronage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rodrigo Kochenburger
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-02-
|
12
|
+
date: 2010-02-18 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -52,7 +52,7 @@ dependencies:
|
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: "0"
|
54
54
|
version:
|
55
|
-
description:
|
55
|
+
description: Generic and simple webservice client library built on top of Patron, which uses libcurl
|
56
56
|
email: divoxx@gmail.com
|
57
57
|
executables: []
|
58
58
|
|
@@ -62,8 +62,22 @@ extra_rdoc_files:
|
|
62
62
|
- LICENSE
|
63
63
|
- README.rdoc
|
64
64
|
files:
|
65
|
+
- .document
|
66
|
+
- .gitignore
|
65
67
|
- LICENSE
|
66
68
|
- README.rdoc
|
69
|
+
- Rakefile
|
70
|
+
- VERSION
|
71
|
+
- features/patronage.feature
|
72
|
+
- features/step_definitions/patronage_steps.rb
|
73
|
+
- features/support/env.rb
|
74
|
+
- lib/patronage.rb
|
75
|
+
- lib/patronage/api.rb
|
76
|
+
- lib/patronage/response.rb
|
77
|
+
- lib/patronage/service.rb
|
78
|
+
- patronage.gemspec
|
79
|
+
- spec/patronage_spec.rb
|
80
|
+
- spec/spec_helper.rb
|
67
81
|
has_rdoc: true
|
68
82
|
homepage: http://github.com/divoxx/patronage
|
69
83
|
licenses: []
|
@@ -92,5 +106,6 @@ rubygems_version: 1.3.5
|
|
92
106
|
signing_key:
|
93
107
|
specification_version: 3
|
94
108
|
summary: Generic and simple webservice client library built on top of Patron, which uses libcurl
|
95
|
-
test_files:
|
96
|
-
|
109
|
+
test_files:
|
110
|
+
- spec/patronage_spec.rb
|
111
|
+
- spec/spec_helper.rb
|