shutl_resource 0.8.2 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -11,3 +11,4 @@ vendor
11
11
 
12
12
  pkg
13
13
  Gemfile.lock
14
+ bin
@@ -63,7 +63,7 @@ module Shutl::Resource
63
63
  end
64
64
 
65
65
  def respond_to? method
66
- self.instance_variables.include?(:"@#{method}")
66
+ self.instance_variables.include?(:"@#{method}") ? true : super
67
67
  end
68
68
 
69
69
  def parsed
@@ -5,9 +5,9 @@ module Shutl::Resource
5
5
  id = args
6
6
  args = { resource_id_name => id }
7
7
  end
8
- token = params.delete :auth
8
+ auth_options = { auth: params.delete(:auth), from: params.delete(:from) }
9
9
  url = member_url args.dup, params
10
- response = get url, headers_with_auth(token)
10
+ response = get url, headers_with_auth(auth_options)
11
11
 
12
12
 
13
13
  check_fail response, "Failed to find #{name} with the id #{id}"
@@ -23,9 +23,11 @@ module Shutl::Resource
23
23
  url = generate_collection_url attributes
24
24
  attributes.delete "response"
25
25
 
26
- response = post(url,
27
- {body: {@resource_name => attributes}.to_json}.
28
- merge(headers_with_auth options[:auth]))
26
+ response = post(
27
+ url,
28
+ {body: {@resource_name => attributes}.to_json}.
29
+ merge(headers_with_auth(options))
30
+ )
29
31
 
30
32
  check_fail response, "Create failed"
31
33
 
@@ -41,7 +43,7 @@ module Shutl::Resource
41
43
  perform_action(
42
44
  instance,
43
45
  :delete,
44
- headers_with_auth(options[:auth]),
46
+ headers_with_auth(options),
45
47
  message
46
48
  ).success?
47
49
  end
@@ -51,7 +53,7 @@ module Shutl::Resource
51
53
  attributes = instance.attributes rescue instance
52
54
 
53
55
  response = perform_action instance, :put,
54
- {body: {@resource_name => convert_new_id(attributes)}.to_json}.merge(headers_with_auth options[:auth]),
56
+ {body: {@resource_name => convert_new_id(attributes)}.to_json}.merge(headers_with_auth options),
55
57
  "Save failed"
56
58
 
57
59
  response.success?
@@ -63,14 +65,14 @@ module Shutl::Resource
63
65
 
64
66
 
65
67
  def all(args = {})
66
- token = args.delete :auth
68
+ auth_options = { auth: args.delete(:auth), from: args.delete(:from) }
67
69
  partition = args.partition {|key,value| !remote_collection_url.index(":#{key}").nil? }
68
70
 
69
71
  url_args = partition.first.inject({}) { |h,pair| h[pair.first] = pair.last ; h }
70
72
  params = partition.last. inject({}) { |h,pair| h[pair.first] = pair.last ; h }
71
73
 
72
74
  url = generate_collection_url url_args, params
73
- response = get url, headers_with_auth(token)
75
+ response = get url, headers_with_auth(auth_options)
74
76
 
75
77
  check_fail response, "Failed to find all #{name.downcase.pluralize}"
76
78
 
@@ -141,8 +143,12 @@ module Shutl::Resource
141
143
 
142
144
  private
143
145
 
144
- def headers_with_auth token
145
- { headers: headers.merge('Authorization' => "Bearer #{token}") }
146
+ def headers_with_auth options = {}
147
+ headers.tap do |h|
148
+ h['Authorization'] = "Bearer #{options[:auth]}" if options[:auth]
149
+ h['From'] = "#{options[:from]}" if options[:from]
150
+ end
151
+ { headers: headers }
146
152
  end
147
153
 
148
154
  def perform_action instance, verb, args, failure_message
@@ -1,5 +1,5 @@
1
1
  module Shutl
2
2
  module Resource
3
- VERSION = '0.8.2'
3
+ VERSION = '0.8.3'
4
4
  end
5
5
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Shutl::Resource::Rest do
4
4
  let(:headers) do
5
- {'Accept'=>'application/json', 'Authorization'=>'Bearer', 'Content-Type'=>'application/json'}
5
+ {'Accept'=>'application/json', 'Content-Type'=>'application/json'}
6
6
  end
7
7
 
8
8
  it 'should include the REST verb' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shutl_resource
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.8.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-04-30 00:00:00.000000000 Z
14
+ date: 2013-05-15 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: httparty
@@ -146,53 +146,18 @@ email:
146
146
  - davidr@shutl.co.uk
147
147
  - volker@shutl.com
148
148
  - mark@shutl.com
149
- executables:
150
- - autospec
151
- - erubis
152
- - htmldiff
153
- - httparty
154
- - httpclient
155
- - ldiff
156
- - rackup
157
- - rails
158
- - rake
159
- - rake2thor
160
- - rdebug
161
- - ri
162
- - rspec
163
- - sprockets
164
- - thor
165
- - tilt
166
- - tt
149
+ executables: []
167
150
  extensions: []
168
151
  extra_rdoc_files: []
169
152
  files:
170
153
  - .gitignore
171
154
  - .rbenv-version
172
155
  - .rspec
173
- - .rvmrc
174
156
  - .travis.yml
175
157
  - Gemfile
176
158
  - LICENSE
177
159
  - README.md
178
160
  - Rakefile
179
- - bin/autospec
180
- - bin/erubis
181
- - bin/htmldiff
182
- - bin/httparty
183
- - bin/httpclient
184
- - bin/ldiff
185
- - bin/rackup
186
- - bin/rails
187
- - bin/rake
188
- - bin/rake2thor
189
- - bin/rdebug
190
- - bin/ri
191
- - bin/rspec
192
- - bin/sprockets
193
- - bin/thor
194
- - bin/tilt
195
- - bin/tt
196
161
  - lib/shutl/resource/configuration.rb
197
162
  - lib/shutl/resource/errors.rb
198
163
  - lib/shutl/resource/rest.rb
@@ -222,7 +187,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
222
187
  version: '0'
223
188
  segments:
224
189
  - 0
225
- hash: -2642824011993525669
190
+ hash: -1347200737366496941
226
191
  required_rubygems_version: !ruby/object:Gem::Requirement
227
192
  none: false
228
193
  requirements:
@@ -231,7 +196,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
231
196
  version: '0'
232
197
  segments:
233
198
  - 0
234
- hash: -2642824011993525669
199
+ hash: -1347200737366496941
235
200
  requirements: []
236
201
  rubyforge_project:
237
202
  rubygems_version: 1.8.24
data/.rvmrc DELETED
@@ -1,48 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
- # development environment upon cd'ing into the directory
5
-
6
- # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
- # Only full ruby name is supported here, for short names use:
8
- # echo "rvm use 1.9.3" > .rvmrc
9
- environment_id="ruby-1.9.3-p362@shutl_resource"
10
-
11
- # Uncomment the following lines if you want to verify rvm version per project
12
- # rvmrc_rvm_version="1.17.2 (stable)" # 1.10.1 seams as a safe start
13
- # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
- # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
- # return 1
16
- # }
17
-
18
- # First we attempt to load the desired environment directly from the environment
19
- # file. This is very fast and efficient compared to running through the entire
20
- # CLI and selector. If you want feedback on which environment was used then
21
- # insert the word 'use' after --create as this triggers verbose mode.
22
- if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
23
- && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
24
- then
25
- \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
26
- [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
27
- \. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
28
- else
29
- # If the environment file has not yet been created, use the RVM CLI to select.
30
- rvm --create "$environment_id" || {
31
- echo "Failed to create RVM environment '${environment_id}'."
32
- return 1
33
- }
34
- fi
35
-
36
- # If you use bundler, this might be useful to you:
37
- # if [[ -s Gemfile ]] && {
38
- # ! builtin command -v bundle >/dev/null ||
39
- # builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
40
- # }
41
- # then
42
- # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
43
- # gem install bundler
44
- # fi
45
- # if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
46
- # then
47
- # bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
48
- # fi
data/bin/autospec DELETED
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # This file was generated by Bundler.
4
- #
5
- # The application 'autospec' is installed as part of a gem, and
6
- # this file is here to facilitate running it.
7
- #
8
-
9
- require 'pathname'
10
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
- Pathname.new(__FILE__).realpath)
12
-
13
- require 'rubygems'
14
- require 'bundler/setup'
15
-
16
- load Gem.bin_path('rspec-core', 'autospec')
data/bin/erubis DELETED
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # This file was generated by Bundler.
4
- #
5
- # The application 'erubis' is installed as part of a gem, and
6
- # this file is here to facilitate running it.
7
- #
8
-
9
- require 'pathname'
10
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
- Pathname.new(__FILE__).realpath)
12
-
13
- require 'rubygems'
14
- require 'bundler/setup'
15
-
16
- load Gem.bin_path('erubis', 'erubis')
data/bin/htmldiff DELETED
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # This file was generated by Bundler.
4
- #
5
- # The application 'htmldiff' is installed as part of a gem, and
6
- # this file is here to facilitate running it.
7
- #
8
-
9
- require 'pathname'
10
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
- Pathname.new(__FILE__).realpath)
12
-
13
- require 'rubygems'
14
- require 'bundler/setup'
15
-
16
- load Gem.bin_path('diff-lcs', 'htmldiff')
data/bin/httparty DELETED
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # This file was generated by Bundler.
4
- #
5
- # The application 'httparty' is installed as part of a gem, and
6
- # this file is here to facilitate running it.
7
- #
8
-
9
- require 'pathname'
10
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
- Pathname.new(__FILE__).realpath)
12
-
13
- require 'rubygems'
14
- require 'bundler/setup'
15
-
16
- load Gem.bin_path('httparty', 'httparty')
data/bin/httpclient DELETED
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # This file was generated by Bundler.
4
- #
5
- # The application 'httpclient' is installed as part of a gem, and
6
- # this file is here to facilitate running it.
7
- #
8
-
9
- require 'pathname'
10
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
- Pathname.new(__FILE__).realpath)
12
-
13
- require 'rubygems'
14
- require 'bundler/setup'
15
-
16
- load Gem.bin_path('httpclient', 'httpclient')
data/bin/ldiff DELETED
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # This file was generated by Bundler.
4
- #
5
- # The application 'ldiff' is installed as part of a gem, and
6
- # this file is here to facilitate running it.
7
- #
8
-
9
- require 'pathname'
10
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
- Pathname.new(__FILE__).realpath)
12
-
13
- require 'rubygems'
14
- require 'bundler/setup'
15
-
16
- load Gem.bin_path('diff-lcs', 'ldiff')
data/bin/rackup DELETED
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # This file was generated by Bundler.
4
- #
5
- # The application 'rackup' is installed as part of a gem, and
6
- # this file is here to facilitate running it.
7
- #
8
-
9
- require 'pathname'
10
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
- Pathname.new(__FILE__).realpath)
12
-
13
- require 'rubygems'
14
- require 'bundler/setup'
15
-
16
- load Gem.bin_path('rack', 'rackup')
data/bin/rails DELETED
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # This file was generated by Bundler.
4
- #
5
- # The application 'rails' is installed as part of a gem, and
6
- # this file is here to facilitate running it.
7
- #
8
-
9
- require 'pathname'
10
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
- Pathname.new(__FILE__).realpath)
12
-
13
- require 'rubygems'
14
- require 'bundler/setup'
15
-
16
- load Gem.bin_path('railties', 'rails')
data/bin/rake DELETED
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # This file was generated by Bundler.
4
- #
5
- # The application 'rake' is installed as part of a gem, and
6
- # this file is here to facilitate running it.
7
- #
8
-
9
- require 'pathname'
10
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
- Pathname.new(__FILE__).realpath)
12
-
13
- require 'rubygems'
14
- require 'bundler/setup'
15
-
16
- load Gem.bin_path('rake', 'rake')
data/bin/rake2thor DELETED
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # This file was generated by Bundler.
4
- #
5
- # The application 'rake2thor' is installed as part of a gem, and
6
- # this file is here to facilitate running it.
7
- #
8
-
9
- require 'pathname'
10
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
- Pathname.new(__FILE__).realpath)
12
-
13
- require 'rubygems'
14
- require 'bundler/setup'
15
-
16
- load Gem.bin_path('thor', 'rake2thor')
data/bin/rdebug DELETED
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # This file was generated by Bundler.
4
- #
5
- # The application 'rdebug' is installed as part of a gem, and
6
- # this file is here to facilitate running it.
7
- #
8
-
9
- require 'pathname'
10
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
- Pathname.new(__FILE__).realpath)
12
-
13
- require 'rubygems'
14
- require 'bundler/setup'
15
-
16
- load Gem.bin_path('debugger', 'rdebug')
data/bin/ri DELETED
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # This file was generated by Bundler.
4
- #
5
- # The application 'ri' is installed as part of a gem, and
6
- # this file is here to facilitate running it.
7
- #
8
-
9
- require 'pathname'
10
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
- Pathname.new(__FILE__).realpath)
12
-
13
- require 'rubygems'
14
- require 'bundler/setup'
15
-
16
- load Gem.bin_path('rdoc', 'ri')
data/bin/rspec DELETED
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # This file was generated by Bundler.
4
- #
5
- # The application 'rspec' is installed as part of a gem, and
6
- # this file is here to facilitate running it.
7
- #
8
-
9
- require 'pathname'
10
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
- Pathname.new(__FILE__).realpath)
12
-
13
- require 'rubygems'
14
- require 'bundler/setup'
15
-
16
- load Gem.bin_path('rspec-core', 'rspec')
data/bin/sprockets DELETED
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # This file was generated by Bundler.
4
- #
5
- # The application 'sprockets' is installed as part of a gem, and
6
- # this file is here to facilitate running it.
7
- #
8
-
9
- require 'pathname'
10
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
- Pathname.new(__FILE__).realpath)
12
-
13
- require 'rubygems'
14
- require 'bundler/setup'
15
-
16
- load Gem.bin_path('sprockets', 'sprockets')
data/bin/thor DELETED
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # This file was generated by Bundler.
4
- #
5
- # The application 'thor' is installed as part of a gem, and
6
- # this file is here to facilitate running it.
7
- #
8
-
9
- require 'pathname'
10
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
- Pathname.new(__FILE__).realpath)
12
-
13
- require 'rubygems'
14
- require 'bundler/setup'
15
-
16
- load Gem.bin_path('thor', 'thor')
data/bin/tilt DELETED
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # This file was generated by Bundler.
4
- #
5
- # The application 'tilt' is installed as part of a gem, and
6
- # this file is here to facilitate running it.
7
- #
8
-
9
- require 'pathname'
10
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
- Pathname.new(__FILE__).realpath)
12
-
13
- require 'rubygems'
14
- require 'bundler/setup'
15
-
16
- load Gem.bin_path('tilt', 'tilt')
data/bin/tt DELETED
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # This file was generated by Bundler.
4
- #
5
- # The application 'tt' is installed as part of a gem, and
6
- # this file is here to facilitate running it.
7
- #
8
-
9
- require 'pathname'
10
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
- Pathname.new(__FILE__).realpath)
12
-
13
- require 'rubygems'
14
- require 'bundler/setup'
15
-
16
- load Gem.bin_path('treetop', 'tt')