apitizer 0.0.2 → 0.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 40fc294404896c8bf5da7bcc98d9a1fb4888d559
4
- data.tar.gz: 0f20b6555f17c71ed78843794b7b37c9b3e1abb8
3
+ metadata.gz: a2b8ff93fa7f78efed6e935c176d6f9ff3323faf
4
+ data.tar.gz: 5da515bb449d54753870d85872aa91dfddbad6d9
5
5
  SHA512:
6
- metadata.gz: 4a38a7ce97d22a84accc45630b5810a36875e300dcfb097c90ceb05ca809ce4b80122bdd54350d35972c2ec04789cd0f260c3355f003a598a7fc43bfea2000ec
7
- data.tar.gz: 20a7a1afa6a79245ac342635422fcfae978f22f70b75651d9287a813b5bfb0f4057da601dea5d60b62f19c0253b9341de200b2f177088e77811931143f03e174
6
+ metadata.gz: b25f42624fd95badd0f04af17494d3b763e1f280ab4c217663449497a3d29f9df40e4ad90124d97deea389037e0dcbad37238fde4d7ccf71027132ca46fcd0ae
7
+ data.tar.gz: 5bcdceb62d92026e806511f501ddb399f52ecdd1f5f5caebac99798d3d41738162e41e20cda7e773cefaf20c365fdba8919e5f956e70aeeaaae3f983f79f414d
@@ -1,6 +1,9 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - 1.9.3
4
+ - 2.0.0
3
5
  - 2.1.0
6
+
4
7
  branches:
5
8
  only:
6
9
  - master
@@ -1,3 +1,7 @@
1
+ ## Apitizer 0.0.3 (July 24, 2014)
2
+
3
+ * Support for Ruby >= 1.9.3 instead of Ruby >= 2.1.
4
+
1
5
  ## Apitizer 0.0.2 (July 20, 2014)
2
6
 
3
7
  * A new strategy for searching request endpoints.
data/Guardfile CHANGED
@@ -1,4 +1,4 @@
1
- guard :rspec do
1
+ guard :rspec, cmd: 'bundle exec rspec' do
2
2
  watch(%r{^spec/.+_spec\.rb$})
3
3
  watch(%r{^spec/.+_helper\.rb$}) { 'spec' }
4
4
  watch(%r{^lib/(.+)\.rb$}) do |match|
data/README.md CHANGED
@@ -22,8 +22,6 @@ Alternatively, you can install the gem manually:
22
22
  $ gem install apitizer
23
23
  ```
24
24
 
25
- Note that the minimal supported version of Ruby is `2.1`.
26
-
27
25
  ## Usage
28
26
 
29
27
  Create an apitizer describing the API of the Web service you would like
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^spec/})
19
19
  spec.require_paths = [ 'lib' ]
20
20
 
21
- spec.required_ruby_version = '>= 2.1'
21
+ spec.required_ruby_version = '>= 1.9.3'
22
22
 
23
23
  spec.add_dependency 'rack', '~> 1.5'
24
24
  spec.add_dependency 'json', '~> 1.8'
@@ -4,7 +4,7 @@ module Apitizer
4
4
 
5
5
  def_delegator :map, :define
6
6
 
7
- def initialize(**options, &block)
7
+ def initialize(options = {}, &block)
8
8
  @options = Helper.deep_merge(Apitizer.defaults, options)
9
9
  @block = block
10
10
  end
@@ -41,7 +41,7 @@ module Apitizer
41
41
  def prepare(action, *path)
42
42
  action = action.to_sym
43
43
  method = @options[:dictionary][action] or raise Error, 'Unknown action'
44
- parameters = path.last.is_a?(Hash) ? path.pop : {}
44
+ parameters = Helper.extract_hash!(path)
45
45
  steps = path.flatten.map(&:to_sym)
46
46
 
47
47
  [ action, method, steps, parameters ]
@@ -6,10 +6,12 @@ module Apitizer
6
6
  module Adaptor
7
7
  class Standard
8
8
  def process(method, address, parameters = {}, headers = {})
9
+ uri = URI(address)
10
+
9
11
  request = build_request(method, address, parameters)
10
12
  headers.each { |k, v| request[k] = v }
11
13
 
12
- http = Net::HTTP.new(request.uri.host, request.uri.port)
14
+ http = Net::HTTP.new(uri.host, uri.port)
13
15
  http.use_ssl = true if address =~ /^https:/
14
16
 
15
17
  response = http.request(request)
@@ -27,15 +29,14 @@ module Apitizer
27
29
  def build_request(method, address, parameters)
28
30
  klass = Net::HTTP.const_get(method.to_s.capitalize)
29
31
 
30
- return klass.new(URI(address)) if parameters.empty?
32
+ return klass.new(address) if parameters.empty?
31
33
 
32
34
  parameters = Helper.build_query(parameters)
33
35
 
34
36
  if klass == Net::HTTP::Get
35
- address = [ address, parameters ].join('?')
36
- request = klass.new(URI(address))
37
+ request = klass.new([ address, parameters ].join('?'))
37
38
  else
38
- request = klass.new(URI(address))
39
+ request = klass.new(address)
39
40
  request.body = parameters
40
41
  request['Content-Type'] = [
41
42
  'application/x-www-form-urlencoded',
@@ -1,10 +1,11 @@
1
1
  module Apitizer
2
2
  module Connection
3
3
  class Dispatcher
4
- def initialize(format:, adaptor: :standard, headers: {})
5
- @format = Format.build(format)
6
- @adaptor = Adaptor.build(adaptor)
7
- @headers = headers.merge('Accept' => @format.mime_type)
4
+ def initialize(options)
5
+ @format = Format.build(options.fetch(:format))
6
+ @adaptor = Adaptor.build(options[:adaptor] || :standard)
7
+ @headers = options[:headers] || {}
8
+ @headers.merge!('Accept' => @format.mime_type)
8
9
  end
9
10
 
10
11
  def process(request)
@@ -6,10 +6,10 @@ module Apitizer
6
6
  attr_reader :method, :path, :parameters
7
7
  def_delegator :path, :address
8
8
 
9
- def initialize(method:, path:, parameters: {})
10
- @method = method
11
- @path = path
12
- @parameters = parameters
9
+ def initialize(options)
10
+ @method = options.fetch(:method)
11
+ @path = options.fetch(:path)
12
+ @parameters = options[:parameters] || {}
13
13
  end
14
14
  end
15
15
  end
@@ -3,9 +3,9 @@ module Apitizer
3
3
  class Response
4
4
  attr_reader :code, :content
5
5
 
6
- def initialize(code:, content:)
7
- @code = code
8
- @content = content
6
+ def initialize(options)
7
+ @code = options.fetch(:code)
8
+ @content = options.fetch(:content)
9
9
  end
10
10
  end
11
11
  end
@@ -25,6 +25,10 @@ module Apitizer
25
25
  one.merge(two, &merger)
26
26
  end
27
27
 
28
+ def self.extract_hash!(arguments)
29
+ arguments.last.is_a?(Hash) ? arguments.pop : {}
30
+ end
31
+
28
32
  def self.build_query(parameters)
29
33
  query = Rack::Utils.build_nested_query(prepare_parameters(parameters))
30
34
  query.encode!('UTF-8')
@@ -6,10 +6,10 @@ module Apitizer
6
6
  def_delegator :@response, :code
7
7
  def_delegators :__getobj__, :is_a?, :kind_of?, :instance_of?
8
8
 
9
- def initialize(request:, response:)
10
- super(response.content)
11
- @request = request
12
- @response = response
9
+ def initialize(options)
10
+ @request = options.fetch(:request)
11
+ @response = options.fetch(:response)
12
+ super(@response.content)
13
13
  end
14
14
  end
15
15
  end
@@ -21,8 +21,9 @@ module Apitizer
21
21
  proxy.instance_eval(&block)
22
22
  end
23
23
 
24
- def define_resources(name, parent: @root, **options, &block)
25
- child = Node::Collection.new(name, **options)
24
+ def define_resources(name, options, &block)
25
+ parent = options.delete(:parent) || @root
26
+ child = Node::Collection.new(name, options)
26
27
  parent.append(child)
27
28
  return unless block_given?
28
29
  proxy = Proxy.new(self, parent: child)
@@ -30,8 +31,9 @@ module Apitizer
30
31
  end
31
32
 
32
33
  Apitizer.actions.each do |action|
33
- define_method "define_#{ action }" do |name, parent:, **options|
34
- child = Node::Operation.new(name, action: action, **options)
34
+ define_method "define_#{ action }" do |name, options|
35
+ parent = options.delete(:parent)
36
+ child = Node::Operation.new(name, options.merge(action: action))
35
37
  parent.append(child)
36
38
  end
37
39
  end
@@ -25,7 +25,7 @@ module Apitizer
25
25
  def recognize?(steps)
26
26
  end
27
27
 
28
- def permit?(action, on:)
28
+ def permit?(action, options)
29
29
  end
30
30
 
31
31
  private
@@ -2,8 +2,10 @@ module Apitizer
2
2
  module Routing
3
3
  module Node
4
4
  class Collection < Base
5
- def initialize(name, only: nil, except: [])
5
+ def initialize(name, options = {})
6
6
  @name = name
7
+ only = options[:only]
8
+ except = options[:except] || []
7
9
  @actions = (only && Array(only) || Apitizer.actions) - Array(except)
8
10
  end
9
11
 
@@ -11,8 +13,9 @@ module Apitizer
11
13
  @name == steps.first
12
14
  end
13
15
 
14
- def permit?(action, on:)
15
- @actions.include?(action) && on == Helper.action_scope(action)
16
+ def permit?(action, options)
17
+ @actions.include?(action) &&
18
+ Helper.action_scope(action) == options.fetch(:on)
16
19
  end
17
20
 
18
21
  private
@@ -2,18 +2,18 @@ module Apitizer
2
2
  module Routing
3
3
  module Node
4
4
  class Operation < Base
5
- def initialize(name, action:, on:)
5
+ def initialize(name, options = {})
6
6
  @name = name
7
- @action = action
8
- @on = on
7
+ @action = options.fetch(:action)
8
+ @on = options.fetch(:on)
9
9
  end
10
10
 
11
11
  def recognize?(steps)
12
12
  @name == steps.first || @name.to_s =~ /^:/
13
13
  end
14
14
 
15
- def permit?(action, on:)
16
- @action == action && @on == on
15
+ def permit?(action, options)
16
+ @action == action && @on == options.fetch(:on)
17
17
  end
18
18
 
19
19
  def on?(on)
@@ -3,19 +3,19 @@ module Apitizer
3
3
  class Path
4
4
  attr_reader :steps, :node
5
5
 
6
- def initialize(steps: [], node: nil)
7
- @steps = steps
8
- @node = node
6
+ def initialize(options = {})
7
+ @steps = options[:steps] || []
8
+ @node = options[:node]
9
9
  end
10
10
 
11
11
  def address
12
12
  @steps.map(&:to_s).join('/')
13
13
  end
14
14
 
15
- def advance(step, node:, on: nil)
15
+ def advance(step, options)
16
16
  @steps << step
17
- @node = node
18
- @on = on
17
+ @node = options.fetch(:node)
18
+ @on = options[:on]
19
19
  end
20
20
 
21
21
  def permit?(action)
@@ -1,16 +1,16 @@
1
1
  module Apitizer
2
2
  module Routing
3
3
  class Proxy
4
- def initialize(owner, **options)
4
+ def initialize(owner, options = {})
5
5
  @owner = owner
6
6
  @options = options
7
7
  end
8
8
 
9
- def method_missing(name, *arguments, **options, &block)
9
+ def method_missing(name, *arguments, &block)
10
10
  name = :"define_#{ name }"
11
11
  return super unless @owner.respond_to?(name)
12
- # NOTE: https://bugs.ruby-lang.org/issues/9776
13
- @owner.send(name, *arguments, **options, **@options, &block)
12
+ options = Helper.extract_hash!(arguments)
13
+ @owner.send(name, *arguments, options.merge(@options), &block)
14
14
  end
15
15
  end
16
16
  end
@@ -1,3 +1,3 @@
1
1
  module Apitizer
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
@@ -4,7 +4,7 @@ RSpec.describe Apitizer::Connection::Adaptor do
4
4
  let(:parent_module) { Apitizer::Connection }
5
5
  let(:address) { 'https://service.com/api/articles' }
6
6
 
7
- shared_examples 'a proper postman' do |method:|
7
+ shared_examples 'a proper postman' do |method|
8
8
  it 'takes into account headers' do
9
9
  headers = { 'Secret-Token' => 'arbitrary' }
10
10
  stub = stub_http_request(method, address).with(headers: headers)
@@ -13,7 +13,7 @@ RSpec.describe Apitizer::Connection::Adaptor do
13
13
  end
14
14
  end
15
15
 
16
- shared_examples '#call of a Rack app' do |method:|
16
+ shared_examples '#call of a Rack app' do |method|
17
17
  let(:code) { 200 }
18
18
  let(:headers) { { 'a' => [ 'b' ] } }
19
19
  let(:body) { 'Hej!' }
@@ -60,8 +60,8 @@ RSpec.describe Apitizer::Connection::Adaptor do
60
60
  describe '#process' do
61
61
  [ :get ].each do |method|
62
62
  context "when sending #{ method } requests" do
63
- it_behaves_like '#call of a Rack app', method: method
64
- it_behaves_like 'a proper postman', method: method
63
+ it_behaves_like '#call of a Rack app', method
64
+ it_behaves_like 'a proper postman', method
65
65
 
66
66
  it 'encodes parameters into the URI' do
67
67
  stub = stub_http_request(method, address).with(query: { life: 42 })
@@ -73,8 +73,8 @@ RSpec.describe Apitizer::Connection::Adaptor do
73
73
 
74
74
  [ :post, :put, :patch, :delete ].each do |method|
75
75
  context "when sending #{ method } requests" do
76
- it_behaves_like '#call of a Rack app', method: method
77
- it_behaves_like 'a proper postman', method: method
76
+ it_behaves_like '#call of a Rack app', method
77
+ it_behaves_like 'a proper postman', method
78
78
 
79
79
  it 'encodes parameters into the body' do
80
80
  stub = stub_http_request(method, address).with(body: 'life=42')
@@ -10,7 +10,7 @@ RSpec.describe Apitizer::Routing::Node do
10
10
  end
11
11
  end
12
12
 
13
- shared_examples 'an adequate collection guard' do |only: restful_actions|
13
+ shared_examples 'an adequate collection guard' do |only = restful_actions|
14
14
  (restful_collection_actions & only).each do |action|
15
15
  it "permits #{ action } actions" do
16
16
  path = root.trace(steps)
@@ -33,7 +33,7 @@ RSpec.describe Apitizer::Routing::Node do
33
33
  end
34
34
  end
35
35
 
36
- shared_examples 'an adequate member guard' do |only: restful_actions|
36
+ shared_examples 'an adequate member guard' do |only = restful_actions|
37
37
  (restful_member_actions & only).each do |action|
38
38
  it "permites #{ action } actions" do
39
39
  path = root.trace(steps)
@@ -96,13 +96,13 @@ RSpec.describe Apitizer::Routing::Node do
96
96
  context 'when looking for collections' do
97
97
  let(:steps) { [ :articles ] }
98
98
  it_behaves_like 'an adequate pathfinder'
99
- it_behaves_like 'an adequate collection guard', only: only
99
+ it_behaves_like 'an adequate collection guard', only
100
100
  end
101
101
 
102
102
  context 'when looking for members' do
103
103
  let(:steps) { [ :articles, 'xxx' ] }
104
104
  it_behaves_like 'an adequate pathfinder'
105
- it_behaves_like 'an adequate member guard', only: only
105
+ it_behaves_like 'an adequate member guard', only
106
106
  end
107
107
  end
108
108
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apitizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Ukhov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-20 00:00:00.000000000 Z
11
+ date: 2014-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -175,7 +175,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
175
175
  requirements:
176
176
  - - ">="
177
177
  - !ruby/object:Gem::Version
178
- version: '2.1'
178
+ version: 1.9.3
179
179
  required_rubygems_version: !ruby/object:Gem::Requirement
180
180
  requirements:
181
181
  - - ">="