tijuana_client 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a1f9f72c08ac31d5156315feb611afe9ab7b4dfb
4
- data.tar.gz: ef8e20b19e777ffeff731f085fbcfe73a39396de
3
+ metadata.gz: 406351a1eca01ee917597abfb197a746505e7fd1
4
+ data.tar.gz: 2116912d9146a74d053443291b820f8f7074f6c2
5
5
  SHA512:
6
- metadata.gz: 6d4b80e21984aa5aa997ba9eed1d0e1f344e01d0b9a14beac40270540d0f1f324543a57a9b241a92175d8ee088a0d1410883ba8259eddeb523c6e92006bf7b5a
7
- data.tar.gz: 7aca41644f92d8608b9639b6c1561d917e908bc729b62a7b1d44b55b22d2e3ff2c462ea8d837eaef76552c52cfc9954d39286984e5845d8d595d7b60fac90d0c
6
+ metadata.gz: 5354d9376642e2d6c81164769404a6e472f5a22533f266aa923f7604e43652d6731a1a1d62ebb1c2a296a5c50b713fcf7206d7bdcc3e6fb79c54833951b98ffd
7
+ data.tar.gz: c33b56c80fed8af168a131138e626336bc909129dc33a943173cd2f96ec949c6f214ec4686fcd78f99937bfd197ee892b1eff9f165bc9b55fa33d39590d2b6cb
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem 'vertebrae'
3
+ gem 'vertebrae', path: '/work/vertebrae'
4
4
 
5
5
  # Add dependencies to develop your gem here.
6
6
  # Include everything needed to run rake, tests, features, etc.
data/Gemfile.lock CHANGED
@@ -1,3 +1,12 @@
1
+ PATH
2
+ remote: /work/vertebrae
3
+ specs:
4
+ vertebrae (0.2.0)
5
+ activesupport
6
+ faraday
7
+ faraday_middleware
8
+ hashie
9
+
1
10
  GEM
2
11
  remote: http://rubygems.org/
3
12
  specs:
@@ -21,8 +30,8 @@ GEM
21
30
  debugger-linecache (1.2.0)
22
31
  debugger-ruby_core_source (1.2.3)
23
32
  diff-lcs (1.2.4)
24
- faraday (0.8.7)
25
- multipart-post (~> 1.1)
33
+ faraday (0.8.8)
34
+ multipart-post (~> 1.2.0)
26
35
  faraday_middleware (0.9.0)
27
36
  faraday (>= 0.7.4, < 0.9)
28
37
  git (1.2.5)
@@ -83,14 +92,9 @@ GEM
83
92
  rspec-mocks (2.14.1)
84
93
  safe_yaml (0.9.4)
85
94
  slop (3.4.5)
86
- thread_safe (0.1.0)
95
+ thread_safe (0.1.2)
87
96
  atomic
88
97
  tzinfo (0.3.37)
89
- vertebrae (0.1.6)
90
- activesupport
91
- faraday
92
- faraday_middleware
93
- hashie
94
98
  webmock (1.13.0)
95
99
  addressable (>= 2.2.7)
96
100
  crack (>= 0.3.2)
@@ -104,5 +108,5 @@ DEPENDENCIES
104
108
  pry
105
109
  pry-debugger
106
110
  rspec
107
- vertebrae
111
+ vertebrae!
108
112
  webmock
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.1.0
@@ -1,60 +1,7 @@
1
1
  module TijuanaClient
2
- class Base < Vertebrae::API
2
+ class Base < Vertebrae::Model
3
3
  def normalized_base_path
4
- "/api/#{base_path}/"
4
+ "api/#{base_path}/"
5
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
6
  end
60
7
  end
@@ -1,7 +1,66 @@
1
1
  module TijuanaClient
2
2
  class Client < Vertebrae::API
3
- def user(options={}, &block)
4
- @user ||= TijuanaClient::User.new(current_options.merge(options), &block)
3
+ def user
4
+ @user ||= TijuanaClient::User.new(client: self)
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 default_options
14
+ {
15
+ user_agent: 'TijuanaClient',
16
+ prefix: '',
17
+ content_type: 'application/x-www-form-urlencoded'
18
+ }
19
+ end
20
+
21
+ def request(method, path, params, options) # :nodoc:
22
+ if !::Vertebrae::Request::METHODS.include?(method)
23
+ raise ArgumentError, "unknown http method: #{method}"
24
+ end
25
+
26
+ path = connection.configuration.prefix + '/' + path
27
+
28
+ ::Vertebrae::Base.logger.debug "EXECUTED: #{method} - #{path} with #{params} and #{options}"
29
+
30
+ connection.connection.send(method) do |request|
31
+
32
+ case method.to_sym
33
+ when *(::Vertebrae::Request::METHODS - ::Vertebrae::Request::METHODS_WITH_BODIES)
34
+ request.body = params.delete('data') if params.has_key?('data')
35
+ request.url(path, params)
36
+ when *::Vertebrae::Request::METHODS_WITH_BODIES
37
+ request.path = path
38
+ request.body = extract_data_from_params(params) unless params.empty?
39
+ end
40
+ end
41
+ end
42
+
43
+ def setup
44
+ connection.stack do |builder|
45
+ builder.use Faraday::Request::Multipart
46
+ builder.use Faraday::Request::UrlEncoded
47
+ builder.use Vertebrae::Request::BasicAuth, connection.configuration.authentication if connection.configuration.authenticated?
48
+
49
+ builder.use Faraday::Response::Logger if ENV['DEBUG']
50
+
51
+ builder.use Vertebrae::Response::RaiseError
52
+ builder.adapter connection.configuration.adapter
53
+ end
54
+ end
55
+
56
+ private
57
+
58
+ def extract_data_from_params(params)
59
+ if params.has_key?('data') && params['data'].present?
60
+ return "data=#{params['data']}"
61
+ else
62
+ return params
63
+ end
5
64
  end
6
65
  end
7
66
  end
@@ -5,7 +5,7 @@ module TijuanaClient
5
5
  end
6
6
 
7
7
  def create(params)
8
- post_json_request(normalized_base_path, params)
8
+ client.post_json_request(normalized_base_path, params)
9
9
  end
10
10
  end
11
11
  end
@@ -1,12 +1,10 @@
1
1
  require 'vertebrae'
2
- require 'tijuana_client/configuration'
3
2
  require 'tijuana_client/base'
4
3
  require 'tijuana_client/user'
5
4
  require 'tijuana_client/client'
6
5
 
7
6
  module TijuanaClient
8
7
  extend Vertebrae::Base
9
- include TijuanaClient::Configuration
10
8
 
11
9
  class << self
12
10
  def new(options = {}, &block)
data/spec/client_spec.rb CHANGED
@@ -8,16 +8,10 @@ describe TijuanaClient::Client do
8
8
 
9
9
  context 'process_basic_auth' do
10
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' }
11
+ let(:config) { subject.connection.configuration }
12
+ specify { config.username.should eq 'login' }
13
+ specify { config.password.should eq 'password' }
14
14
  end
15
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
16
  end
23
17
  end
data/spec/spec_helper.rb CHANGED
@@ -36,16 +36,10 @@ def stub_post(path)
36
36
  end
37
37
 
38
38
  def stub_tijuana_request(method, path)
39
- prefix = TijuanaClient.prefix.to_s
39
+ prefix = TijuanaClient.new.connection.configuration.prefix.to_s
40
40
  stub_request(method, "https://test.com" + prefix + path)
41
41
  end
42
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
43
 
50
44
 
51
45
  def fixture_path
data/spec/user_spec.rb CHANGED
@@ -4,24 +4,25 @@ describe TijuanaClient::User do
4
4
  subject { TijuanaClient.new(host: 'test.com') }
5
5
 
6
6
  describe 'configuration' do
7
- it 'should propagate the host to the page' do
8
- subject.user.host.should == 'test.com'
7
+ it 'should propagate the host' do
8
+ subject.user.client.connection.configuration.host.should == 'test.com'
9
9
  end
10
10
  end
11
11
 
12
12
  describe '.post_json_request' do
13
- subject { TijuanaClient::User.new({}) }
13
+ let(:client) { TijuanaClient::Client.new }
14
+ subject { TijuanaClient::User.new({client: client }) }
14
15
  let(:path) { '/foo' }
15
16
  let(:params) { {first_name: 'Nathan'} }
16
17
 
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)
18
+ it 'should jsonify params' do
19
+ client.should_receive(:post_request).with('/foo', {'data' => JSON.generate({ first_name: 'Nathan'}) } )
20
+ client.post_json_request(path, params)
20
21
  end
21
22
  end
22
23
 
23
- describe "create" do
24
- let(:body) { "" }
24
+ describe 'create' do
25
+ let(:body) { '' }
25
26
  let(:request_body) { "data=#{ JSON.generate({ first_name: 'Nathan'})}" }
26
27
  let(:request_path) { '/api/users/' }
27
28
 
@@ -30,18 +31,18 @@ describe TijuanaClient::User do
30
31
  :headers => { content_type: "application/json; charset=utf-8"})
31
32
  end
32
33
 
33
- describe "success" do
34
+ describe 'success' do
34
35
  let(:status) { 200 }
35
36
 
36
- it "should create a user" do
37
+ it 'should create a user' do
37
38
  subject.user.create(first_name: 'Nathan')
38
39
  end
39
40
  end
40
41
 
41
- describe "an error" do
42
+ describe 'an error' do
42
43
  let(:status) { 500 }
43
44
 
44
- it "should return nil" do
45
+ it 'should return nil' do
45
46
  lambda { subject.user.create(first_name: 'Nathan') }.should raise_exception
46
47
  end
47
48
  end
@@ -0,0 +1,74 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "tijuana_client"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Nathan Woodhull"]
12
+ s.date = "2013-07-30"
13
+ s.description = "An API client for the code that runs Getup.org.au"
14
+ s.email = "nathan@controlshiftlabs.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".ruby-gemset",
21
+ ".ruby-version",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.md",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "lib/tijuana_client.rb",
29
+ "lib/tijuana_client/base.rb",
30
+ "lib/tijuana_client/client.rb",
31
+ "lib/tijuana_client/user.rb",
32
+ "spec/client_spec.rb",
33
+ "spec/spec_helper.rb",
34
+ "spec/tijuana_spec.rb",
35
+ "spec/user_spec.rb",
36
+ "tijuana_client.gemspec"
37
+ ]
38
+ s.homepage = "http://github.com/controlshift/tijuana_client"
39
+ s.licenses = ["MIT"]
40
+ s.require_paths = ["lib"]
41
+ s.rubygems_version = "2.0.4"
42
+ s.summary = "API client for Tijuana"
43
+
44
+ if s.respond_to? :specification_version then
45
+ s.specification_version = 4
46
+
47
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
48
+ s.add_runtime_dependency(%q<vertebrae>, [">= 0"])
49
+ s.add_development_dependency(%q<rspec>, [">= 0"])
50
+ s.add_development_dependency(%q<webmock>, [">= 0"])
51
+ s.add_development_dependency(%q<pry>, [">= 0"])
52
+ s.add_development_dependency(%q<pry-debugger>, [">= 0"])
53
+ s.add_development_dependency(%q<bundler>, [">= 0"])
54
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
55
+ else
56
+ s.add_dependency(%q<vertebrae>, [">= 0"])
57
+ s.add_dependency(%q<rspec>, [">= 0"])
58
+ s.add_dependency(%q<webmock>, [">= 0"])
59
+ s.add_dependency(%q<pry>, [">= 0"])
60
+ s.add_dependency(%q<pry-debugger>, [">= 0"])
61
+ s.add_dependency(%q<bundler>, [">= 0"])
62
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
63
+ end
64
+ else
65
+ s.add_dependency(%q<vertebrae>, [">= 0"])
66
+ s.add_dependency(%q<rspec>, [">= 0"])
67
+ s.add_dependency(%q<webmock>, [">= 0"])
68
+ s.add_dependency(%q<pry>, [">= 0"])
69
+ s.add_dependency(%q<pry-debugger>, [">= 0"])
70
+ s.add_dependency(%q<bundler>, [">= 0"])
71
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
72
+ end
73
+ end
74
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tijuana_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Woodhull
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-17 00:00:00.000000000 Z
11
+ date: 2013-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: vertebrae
@@ -127,12 +127,12 @@ files:
127
127
  - lib/tijuana_client.rb
128
128
  - lib/tijuana_client/base.rb
129
129
  - lib/tijuana_client/client.rb
130
- - lib/tijuana_client/configuration.rb
131
130
  - lib/tijuana_client/user.rb
132
131
  - spec/client_spec.rb
133
132
  - spec/spec_helper.rb
134
133
  - spec/tijuana_spec.rb
135
134
  - spec/user_spec.rb
135
+ - tijuana_client.gemspec
136
136
  homepage: http://github.com/controlshift/tijuana_client
137
137
  licenses:
138
138
  - MIT
@@ -1,11 +0,0 @@
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