tijuana_client 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a1f9f72c08ac31d5156315feb611afe9ab7b4dfb
4
+ data.tar.gz: ef8e20b19e777ffeff731f085fbcfe73a39396de
5
+ SHA512:
6
+ metadata.gz: 6d4b80e21984aa5aa997ba9eed1d0e1f344e01d0b9a14beac40270540d0f1f324543a57a9b241a92175d8ee088a0d1410883ba8259eddeb523c6e92006bf7b5a
7
+ data.tar.gz: 7aca41644f92d8608b9639b6c1561d917e908bc729b62a7b1d44b55b22d2e3ff2c462ea8d837eaef76552c52cfc9954d39286984e5845d8d595d7b60fac90d0c
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ tijuana_client
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.0.0-p247
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'vertebrae'
4
+
5
+ # Add dependencies to develop your gem here.
6
+ # Include everything needed to run rake, tests, features, etc.
7
+ group :development do
8
+ gem "rspec"
9
+ gem 'webmock'
10
+ gem 'pry'
11
+ gem 'pry-debugger'
12
+ gem "bundler"
13
+ gem "jeweler", "~> 1.8.4"
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,108 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (4.0.0)
5
+ i18n (~> 0.6, >= 0.6.4)
6
+ minitest (~> 4.2)
7
+ multi_json (~> 1.3)
8
+ thread_safe (~> 0.1)
9
+ tzinfo (~> 0.3.37)
10
+ addressable (2.3.5)
11
+ atomic (1.1.10)
12
+ builder (3.2.2)
13
+ coderay (1.0.9)
14
+ columnize (0.3.6)
15
+ crack (0.4.0)
16
+ safe_yaml (~> 0.9.0)
17
+ debugger (1.6.1)
18
+ columnize (>= 0.3.1)
19
+ debugger-linecache (~> 1.2.0)
20
+ debugger-ruby_core_source (~> 1.2.3)
21
+ debugger-linecache (1.2.0)
22
+ debugger-ruby_core_source (1.2.3)
23
+ diff-lcs (1.2.4)
24
+ faraday (0.8.7)
25
+ multipart-post (~> 1.1)
26
+ faraday_middleware (0.9.0)
27
+ faraday (>= 0.7.4, < 0.9)
28
+ git (1.2.5)
29
+ github_api (0.10.1)
30
+ addressable
31
+ faraday (~> 0.8.1)
32
+ hashie (>= 1.2)
33
+ multi_json (~> 1.4)
34
+ nokogiri (~> 1.5.2)
35
+ oauth2
36
+ hashie (2.0.5)
37
+ highline (1.6.19)
38
+ httpauth (0.2.0)
39
+ i18n (0.6.4)
40
+ jeweler (1.8.6)
41
+ builder
42
+ bundler (~> 1.0)
43
+ git (>= 1.2.5)
44
+ github_api (= 0.10.1)
45
+ highline (>= 1.6.15)
46
+ nokogiri (= 1.5.10)
47
+ rake
48
+ rdoc
49
+ json (1.8.0)
50
+ jwt (0.1.8)
51
+ multi_json (>= 1.5)
52
+ method_source (0.8.1)
53
+ minitest (4.7.5)
54
+ multi_json (1.7.7)
55
+ multi_xml (0.5.4)
56
+ multipart-post (1.2.0)
57
+ nokogiri (1.5.10)
58
+ oauth2 (0.9.2)
59
+ faraday (~> 0.8)
60
+ httpauth (~> 0.2)
61
+ jwt (~> 0.1.4)
62
+ multi_json (~> 1.0)
63
+ multi_xml (~> 0.5)
64
+ rack (~> 1.2)
65
+ pry (0.9.12.2)
66
+ coderay (~> 1.0.5)
67
+ method_source (~> 0.8)
68
+ slop (~> 3.4)
69
+ pry-debugger (0.2.2)
70
+ debugger (~> 1.3)
71
+ pry (~> 0.9.10)
72
+ rack (1.5.2)
73
+ rake (10.1.0)
74
+ rdoc (4.0.1)
75
+ json (~> 1.4)
76
+ rspec (2.14.1)
77
+ rspec-core (~> 2.14.0)
78
+ rspec-expectations (~> 2.14.0)
79
+ rspec-mocks (~> 2.14.0)
80
+ rspec-core (2.14.2)
81
+ rspec-expectations (2.14.0)
82
+ diff-lcs (>= 1.1.3, < 2.0)
83
+ rspec-mocks (2.14.1)
84
+ safe_yaml (0.9.4)
85
+ slop (3.4.5)
86
+ thread_safe (0.1.0)
87
+ atomic
88
+ tzinfo (0.3.37)
89
+ vertebrae (0.1.6)
90
+ activesupport
91
+ faraday
92
+ faraday_middleware
93
+ hashie
94
+ webmock (1.13.0)
95
+ addressable (>= 2.2.7)
96
+ crack (>= 0.3.2)
97
+
98
+ PLATFORMS
99
+ ruby
100
+
101
+ DEPENDENCIES
102
+ bundler
103
+ jeweler (~> 1.8.4)
104
+ pry
105
+ pry-debugger
106
+ rspec
107
+ vertebrae
108
+ webmock
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 ControlShift Ltd.
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.md ADDED
@@ -0,0 +1,4 @@
1
+ tijuana_client_
2
+ =========================
3
+
4
+ An exceptionally simple client for Getup's Tijuana
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "tijuana_client"
18
+ gem.homepage = "http://github.com/controlshift/tijuana_client"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{API client for Tijuana}
21
+ gem.description = %Q{An API client for the code that runs Getup.org.au}
22
+ gem.email = "nathan@controlshiftlabs.com"
23
+ gem.authors = ["Nathan Woodhull"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rdoc/task'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "porpoise_external_actions #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,60 @@
1
+ module TijuanaClient
2
+ class Base < Vertebrae::API
3
+ def normalized_base_path
4
+ "/api/#{base_path}/"
5
+ end
6
+
7
+ def post_json_request(path, params)
8
+ p = {}
9
+ p['data'] = params.to_json
10
+ post_request(path, p)
11
+ end
12
+
13
+ def request(method, path, params, options) # :nodoc:
14
+ if !::Vertebrae::Request::METHODS.include?(method)
15
+ raise ArgumentError, "unknown http method: #{method}"
16
+ end
17
+
18
+ conn = connection(options.merge(current_options))
19
+ path = conn.path_prefix + '/' + path
20
+
21
+ ::Vertebrae::Base.logger.debug "EXECUTED: #{method} - #{path} with #{params} and #{options}"
22
+
23
+ conn.send(method) do |request|
24
+
25
+ case method.to_sym
26
+ when *(::Vertebrae::Request::METHODS - ::Vertebrae::Request::METHODS_WITH_BODIES)
27
+ request.body = params.delete('data') if params.has_key?('data')
28
+ request.url(path, params)
29
+ when *::Vertebrae::Request::METHODS_WITH_BODIES
30
+ request.path = path
31
+ request.body = extract_data_from_params(params) unless params.empty?
32
+ end
33
+ end
34
+ end
35
+
36
+ def default_middleware(options={})
37
+ Proc.new do |builder|
38
+ builder.use Faraday::Request::Multipart
39
+ builder.use Faraday::Request::UrlEncoded
40
+ builder.use Vertebrae::Request::BasicAuth, authentication if authenticated?
41
+
42
+ builder.use Faraday::Response::Logger if ENV['DEBUG']
43
+
44
+ builder.use Vertebrae::Response::RaiseError
45
+ builder.adapter adapter
46
+ end
47
+ end
48
+
49
+ private
50
+
51
+ def extract_data_from_params(params)
52
+ if params.has_key?('data') && params['data'].present?
53
+ return "data=#{params['data']}"
54
+ else
55
+ return params
56
+ end
57
+ end
58
+
59
+ end
60
+ end
@@ -0,0 +1,7 @@
1
+ module TijuanaClient
2
+ class Client < Vertebrae::API
3
+ def user(options={}, &block)
4
+ @user ||= TijuanaClient::User.new(current_options.merge(options), &block)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ module TijuanaClient
2
+ module Configuration
3
+ def self.included(mod)
4
+ Vertebrae::Base.configure do |config|
5
+ config.user_agent = 'TijuanaClient'
6
+ config.prefix = ''
7
+ config.content_type = 'application/x-www-form-urlencoded'
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module TijuanaClient
2
+ class User < Base
3
+ def base_path
4
+ 'users'
5
+ end
6
+
7
+ def create(params)
8
+ post_json_request(normalized_base_path, params)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ require 'vertebrae'
2
+ require 'tijuana_client/configuration'
3
+ require 'tijuana_client/base'
4
+ require 'tijuana_client/user'
5
+ require 'tijuana_client/client'
6
+
7
+ module TijuanaClient
8
+ extend Vertebrae::Base
9
+ include TijuanaClient::Configuration
10
+
11
+ class << self
12
+ def new(options = {}, &block)
13
+ TijuanaClient::Client.new(options, &block)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe TijuanaClient::Client do
4
+ specify { subject.should respond_to :user }
5
+
6
+ describe "instantiated" do
7
+ subject { described_class.new(options) }
8
+
9
+ context 'process_basic_auth' do
10
+ let(:options) { { :basic_auth => 'login:password' } }
11
+ its(:username) { should eq 'login' }
12
+ its(:password) { should eq 'password' }
13
+ its(:basic_auth) { should eq 'login:password' }
14
+ end
15
+
16
+ context "process username & password" do
17
+ let(:options) { { :username => 'login', password: 'password' } }
18
+ its(:username) { should eq 'login' }
19
+ its(:password) { should eq 'password' }
20
+ its(:basic_auth) { should eq 'login:password' }
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,57 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'tijuana_client'
5
+ require 'webmock/rspec'
6
+
7
+
8
+ # Requires supporting files with custom matchers and macros, etc,
9
+ # in ./support/ and its subdirectories.
10
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
11
+
12
+ RSpec.configure do |config|
13
+ config.color_enabled = true
14
+ end
15
+
16
+
17
+ RSpec.configure do |config|
18
+ config.include WebMock::API
19
+
20
+
21
+ config.before(:each) do
22
+ WebMock.reset!
23
+ end
24
+ config.after(:each) do
25
+ WebMock.reset!
26
+ end
27
+
28
+ end
29
+
30
+ def stub_get(path)
31
+ stub_tijuana_request(:get, path)
32
+ end
33
+
34
+ def stub_post(path)
35
+ stub_tijuana_request(:post, path)
36
+ end
37
+
38
+ def stub_tijuana_request(method, path)
39
+ prefix = TijuanaClient.prefix.to_s
40
+ stub_request(method, "https://test.com" + prefix + path)
41
+ end
42
+
43
+ def reset_authentication_for(object)
44
+ [ 'username', 'password' ].each do |item|
45
+ TijuanaClient.send("#{item}=", nil)
46
+ object.send("#{item}=", nil)
47
+ end
48
+ end
49
+
50
+
51
+ def fixture_path
52
+ File.expand_path("../fixtures", __FILE__)
53
+ end
54
+
55
+ def fixture(file)
56
+ File.new(File.join(fixture_path, '/', file))
57
+ end
@@ -0,0 +1,6 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe TijuanaClient do
4
+ specify { subject.should respond_to :user }
5
+ specify { subject.new.should be_a(TijuanaClient::Client)}
6
+ end
data/spec/user_spec.rb ADDED
@@ -0,0 +1,78 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe TijuanaClient::User do
4
+ subject { TijuanaClient.new(host: 'test.com') }
5
+
6
+ describe 'configuration' do
7
+ it 'should propagate the host to the page' do
8
+ subject.user.host.should == 'test.com'
9
+ end
10
+ end
11
+
12
+ describe '.post_json_request' do
13
+ subject { TijuanaClient::User.new({}) }
14
+ let(:path) { '/foo' }
15
+ let(:params) { {first_name: 'Nathan'} }
16
+
17
+ it "should jsonify params" do
18
+ subject.should_receive(:post_request).with('/foo', {'data' => JSON.generate({ first_name: 'Nathan'}) } )
19
+ subject.post_json_request(path, params)
20
+ end
21
+ end
22
+
23
+ describe "create" do
24
+ let(:body) { "" }
25
+ let(:request_body) { "data=#{ JSON.generate({ first_name: 'Nathan'})}" }
26
+ let(:request_path) { '/api/users/' }
27
+
28
+ before(:each) do
29
+ stub_post(request_path).with(body: request_body).to_return(:body => body, :status => status,
30
+ :headers => { content_type: "application/json; charset=utf-8"})
31
+ end
32
+
33
+ describe "success" do
34
+ let(:status) { 200 }
35
+
36
+ it "should create a user" do
37
+ subject.user.create(first_name: 'Nathan')
38
+ end
39
+ end
40
+
41
+ describe "an error" do
42
+ let(:status) { 500 }
43
+
44
+ it "should return nil" do
45
+ lambda { subject.user.create(first_name: 'Nathan') }.should raise_exception
46
+ end
47
+ end
48
+ end
49
+
50
+ describe "basic authentication" do
51
+ subject { TijuanaClient.new(host: 'test.com', username: 'username', password: 'password')}
52
+
53
+ let(:body) { "" }
54
+ let(:request_body) { "data=#{ JSON.generate({ first_name: 'Nathan'})}" }
55
+ let(:request_path) { '/api/users/' }
56
+
57
+ before(:each) do
58
+ stub_request(:post, "https://username:password@test.com#{request_path}").with(body: request_body).to_return(:body => body, :status => status,
59
+ :headers => { content_type: "application/json; charset=utf-8"})
60
+ end
61
+
62
+ describe "success" do
63
+ let(:status) { 200 }
64
+
65
+ it "should create a user" do
66
+ subject.user.create(first_name: 'Nathan')
67
+ end
68
+ end
69
+
70
+ describe "unauthorized" do
71
+ let(:status) { 401 }
72
+
73
+ it "should return nil" do
74
+ lambda { subject.user.create(first_name: 'Nathan') }.should raise_exception
75
+ end
76
+ end
77
+ end
78
+ end
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tijuana_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nathan Woodhull
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: vertebrae
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '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'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: webmock
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
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
+ - !ruby/object:Gem::Dependency
70
+ name: pry-debugger
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: jeweler
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: 1.8.4
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: 1.8.4
111
+ description: An API client for the code that runs Getup.org.au
112
+ email: nathan@controlshiftlabs.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files:
116
+ - LICENSE.txt
117
+ - README.md
118
+ files:
119
+ - .ruby-gemset
120
+ - .ruby-version
121
+ - Gemfile
122
+ - Gemfile.lock
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - VERSION
127
+ - lib/tijuana_client.rb
128
+ - lib/tijuana_client/base.rb
129
+ - lib/tijuana_client/client.rb
130
+ - lib/tijuana_client/configuration.rb
131
+ - lib/tijuana_client/user.rb
132
+ - spec/client_spec.rb
133
+ - spec/spec_helper.rb
134
+ - spec/tijuana_spec.rb
135
+ - spec/user_spec.rb
136
+ homepage: http://github.com/controlshift/tijuana_client
137
+ licenses:
138
+ - MIT
139
+ metadata: {}
140
+ post_install_message:
141
+ rdoc_options: []
142
+ require_paths:
143
+ - lib
144
+ required_ruby_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - '>='
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - '>='
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ requirements: []
155
+ rubyforge_project:
156
+ rubygems_version: 2.0.4
157
+ signing_key:
158
+ specification_version: 4
159
+ summary: API client for Tijuana
160
+ test_files: []