divoxx-patronage 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.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Rodrigo Kochenburger
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,15 @@
1
+ = patronage
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a future version unintentionally.
10
+ * Commit, do not mess with rakefile, version, or history (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull).
11
+ * Send me a pull request. Bonus points for topic branches.
12
+
13
+ == Copyright
14
+
15
+ Copyright (c) 2009 Rodrigo Kochenburger. See LICENSE for details.
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{TODO: longer description of your gem}
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.1
@@ -0,0 +1,9 @@
1
+ Feature: something something
2
+ In order to something something
3
+ A user something something
4
+ something something something
5
+
6
+ Scenario: something something
7
+ Given inspiration
8
+ When I create a sweet new gem
9
+ Then everyone should see how awesome I am
File without changes
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
+ require 'patronage'
3
+
4
+ require 'spec/expectations'
@@ -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)
22
+ Service.new(self, service_name)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,33 @@
1
+ module Patronage
2
+ class Response
3
+ Parsers = {
4
+ /^application\/xml/ => lambda { |body| Hash.from_xml(body) }
5
+ }
6
+
7
+ def initialize(response)
8
+ @response = response
9
+ end
10
+
11
+ def method_missing(meth_name, *args)
12
+ if @response.public_methods.include?(meth_name.to_s)
13
+ @response.send(meth_name, *args)
14
+ else
15
+ super
16
+ end
17
+ end
18
+
19
+ def data
20
+ unless @data
21
+ mime_type = @response.headers["Content-Type"] || @response.headers["Content-type"] || @response.headers["content-Type"]
22
+ parser = Parsers.keys.find { |matcher| matcher === mime_type }
23
+
24
+ if parser
25
+ @data = Parsers[parser].call(@response.body)
26
+ else
27
+ raise ArgumentError, "unknown parser for #{mime_type}"
28
+ end
29
+ end
30
+ @data
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,20 @@
1
+ module Patronage
2
+ class Service
3
+ attr_reader :name
4
+
5
+ def initialize(api, name)
6
+ @api = api
7
+ @name = name.to_s
8
+ end
9
+
10
+ def service_location
11
+ "/#{name}"
12
+ end
13
+
14
+ def get(params)
15
+ uri = Addressable::URI.parse(service_location)
16
+ uri.query_values = params
17
+ Response.new(@api.get(uri.to_s))
18
+ end
19
+ end
20
+ end
data/lib/patronage.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'patronage/api'
2
+ require 'patronage/service'
3
+ require 'patronage/response'
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Patronage" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'patronage'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: divoxx-patronage
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Rodrigo Kochenburger
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-21 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: addressable
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.1.0
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: patron
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.4.2
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: rspec
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: cucumber
47
+ type: :development
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ description: "TODO: longer description of your gem"
56
+ email: divoxx@gmail.com
57
+ executables: []
58
+
59
+ extensions: []
60
+
61
+ extra_rdoc_files:
62
+ - LICENSE
63
+ - README.rdoc
64
+ files:
65
+ - .document
66
+ - .gitignore
67
+ - LICENSE
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
+ - spec/patronage_spec.rb
79
+ - spec/spec_helper.rb
80
+ has_rdoc: false
81
+ homepage: http://github.com/divoxx/patronage
82
+ licenses:
83
+ post_install_message:
84
+ rdoc_options:
85
+ - --charset=UTF-8
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: "0"
93
+ version:
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: "0"
99
+ version:
100
+ requirements: []
101
+
102
+ rubyforge_project:
103
+ rubygems_version: 1.3.5
104
+ signing_key:
105
+ specification_version: 3
106
+ summary: Generic and simple webservice client library built on top of Patron, which uses libcurl
107
+ test_files:
108
+ - spec/patronage_spec.rb
109
+ - spec/spec_helper.rb