callapi 0.9.0 → 0.9.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 666cfc16f86f8bbab5db5e2fbc10b15622111406
4
- data.tar.gz: b9e3dec2a83fad0d45a6913b7c2b323bf5c0a1e3
3
+ metadata.gz: 8f898a143b9e393803f76ee96277c1b1133143f1
4
+ data.tar.gz: 4f009cafe222f8f87b5c03b70dd7b665d11ba04d
5
5
  SHA512:
6
- metadata.gz: c7f45e5636ed00b419e69bbeacca4dedea65bca9b0c859d6279fbb9656c47e16e047c8c38e53b3e816d1f04c49ce108e22c5e0f4ae8c8048eb258213ca1749c3
7
- data.tar.gz: 86bb3292da0e5732199721b23b98d35aca92e6b0278636434d0444077b344f2504f70eed282ca6ca2b8db88261fbdf3b0722dc7a0a5cb6952d122d4f6077ccf2
6
+ metadata.gz: dc5515655a1d29aad17444d7f9a48ba638a22170c8ee8c00d3e6ff3ae85e49e3f3494ab1ecce24c3900dfc3b3833d5abdeebf5b092bcabf8d012b3b1e35f8633
7
+ data.tar.gz: 380dc2706bf5e49092a54bc6aaf023dc80c8f0cfb9b54552d7094bb87494c0de946d6636e39be4c4493ad553c4f34b4fe5212d95c82c56fcde0535067cfe8f4f
@@ -1,4 +1,9 @@
1
- ## 0.8.4 (next release)
1
+ ### 0.9.1 (NEXT RELEASE)
2
+
3
+ - Remove Memoist dependency
4
+ - Instead of `call.response.data` `call.data` can be used
5
+
6
+ ### 0.9
2
7
 
3
8
  - Remove activesupport dependency
4
9
  - URI pattern can be a `Symbol` (before only `String`s were accepted)
@@ -6,21 +11,21 @@
6
11
  - Backward compatibility fix for `#api_path_prefix`
7
12
  - Changelog added
8
13
 
9
- ## 0.8.3
14
+ ### 0.8.3
10
15
 
11
16
  - API path prefix taken from `Config.api_host` (no need to set `Config.api_path_prefix`)
12
17
  - Added Ruby dependency (>= 2.0)
13
18
  - Code Climate refactor
14
19
 
15
- ## 0.8.2
20
+ ### 0.8.2
16
21
 
17
22
  - Bugfix: Critical issue fix (undefined method `#api_path_prefix`)
18
23
 
19
- ## 0.8.1
24
+ ### 0.8.1
20
25
 
21
26
  - Dependencies
22
27
  - Documentation update
23
28
 
24
- ## 0.8
29
+ ### 0.8
25
30
 
26
- - Initial release, after long internal usage
31
+ - Initial release, after long internal usage
data/Gemfile CHANGED
@@ -1,7 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gem 'multi_json'
4
- gem 'memoist'
5
4
  gem 'addressable'
6
5
  gem 'addressabler', '>= 0.1'
7
6
  gem 'colorize'
@@ -27,7 +27,6 @@ Gem::Specification.new do |spec|
27
27
  spec.add_runtime_dependency 'multi_json', '~> 1.10'
28
28
  spec.add_runtime_dependency 'colorize', '~> 0.7'
29
29
  spec.add_runtime_dependency 'chainy', '~> 0.0.5'
30
- spec.add_runtime_dependency 'memoist', '~> 0.11'
31
30
 
32
31
  spec.required_ruby_version = '>= 2.0'
33
32
  end
@@ -1,8 +1,6 @@
1
1
  require 'callapi/version'
2
- require 'memoist'
3
2
  require 'forwardable'
4
3
  require 'chainy'
5
- require 'ostruct'
6
4
  require_relative 'ext/super_string'
7
5
 
8
6
  module Callapi
@@ -7,6 +7,7 @@ class Callapi::Call::Base
7
7
  extend Forwardable
8
8
 
9
9
  def_delegators :request_metadata, :request_method, :request_path
10
+ def_delegators :response, :data, :body
10
11
 
11
12
  chain_attr_accessor :params, :headers, hash: true, prefix: 'add'
12
13
  chain_attr_accessor :response_parser, :strategy
@@ -1,5 +1,4 @@
1
1
  class Callapi::Call::Request::Mock < Callapi::Call::Request::Base
2
- extend Memoist
3
2
  #TODO: should not be hardcoded
4
3
  MOCK_FORMAT = '.json'
5
4
 
@@ -1,6 +1,4 @@
1
1
  class Callapi::Call::RequestMetadata < Struct.new(:context)
2
- extend Memoist
3
-
4
2
  HTTP_METHODS = %w(GET POST PUT PATCH DELETE)
5
3
 
6
4
  def request_method
@@ -10,14 +8,15 @@ class Callapi::Call::RequestMetadata < Struct.new(:context)
10
8
  end
11
9
 
12
10
  def request_path
13
- request_path = request_path_without_replaced_param_keys
11
+ return @request_path if @request_path
12
+
13
+ @request_path = request_path_without_replaced_param_keys
14
14
  param_keys_to_replace.each do |param_key|
15
- param_value = context.params[param_key.to_sym] || raise(Callapi::MissingParamError.new(request_path, param_keys_to_replace, missing_keys))
16
- request_path.sub!(param_key + '_param', param_value.to_s)
15
+ param_value = context.params[param_key.to_sym] || raise_missing_param_error
16
+ @request_path.sub!(param_key + '_param', param_value.to_s)
17
17
  end
18
- request_path
18
+ @request_path
19
19
  end
20
- memoize :request_path
21
20
 
22
21
  private
23
22
 
@@ -26,30 +25,30 @@ class Callapi::Call::RequestMetadata < Struct.new(:context)
26
25
  end
27
26
 
28
27
  def request_path_without_replaced_param_keys
29
- '/' + SuperString.underscore(call_name)
30
- end
31
- memoize :request_path_without_replaced_param_keys
32
-
33
- def missing_keys
34
- (param_keys_to_replace.map(&:to_sym) - context.params.keys).map { |key| ":#{key}" }
28
+ @request_path_without_replaced_param_keys ||= "/#{SuperString.underscore(call_name)}"
35
29
  end
36
30
 
37
31
  def namespaces_after_http_method
38
32
  namespaces[namespaces.index(namespace_with_http_method) + 1 .. namespaces.size]
39
33
  end
40
- memoize :namespaces_after_http_method
41
34
 
42
35
  def namespace_with_http_method
43
36
  namespaces.detect{ |namespace| HTTP_METHODS.include?(namespace.upcase) } || raise(Callapi::UnknownHttpMethodError)
44
37
  end
45
- memoize :namespace_with_http_method
46
38
 
47
39
  def call_name
48
40
  namespaces_after_http_method.join('::')
49
41
  end
50
42
 
51
43
  def namespaces
52
- context.class.to_s.split('::')
44
+ @namespaces ||= context.class.to_s.split('::')
45
+ end
46
+
47
+ def raise_missing_param_error
48
+ raise Callapi::MissingParamError.new(@request_path, param_keys_to_replace, missing_keys)
49
+ end
50
+
51
+ def missing_keys
52
+ (param_keys_to_replace.map(&:to_sym) - context.params.keys).map { |key| ":#{key}" }
53
53
  end
54
- memoize :namespaces
55
54
  end
@@ -4,7 +4,6 @@ class Callapi::Call::Parser
4
4
  require_relative 'response/json'
5
5
  require_relative 'response/json/as_object'
6
6
 
7
- extend Memoist
8
7
  extend Forwardable
9
8
 
10
9
  def_delegators :@response, :body, :code
@@ -14,17 +13,17 @@ class Callapi::Call::Parser
14
13
  end
15
14
 
16
15
  def data
16
+ return @data if @data
17
+
17
18
  raise_error unless ok?
18
19
  return nil if no_content?
19
20
 
20
- parse
21
+ @data = parse
21
22
  end
22
- memoize :data
23
23
 
24
24
  def status
25
25
  code.to_i
26
26
  end
27
- memoize :status
28
27
 
29
28
  private
30
29
 
@@ -35,13 +34,11 @@ class Callapi::Call::Parser
35
34
  def ok?
36
35
  status < 300
37
36
  end
38
- memoize :ok?
39
37
 
40
38
  def no_content?
41
39
  return true if body.nil?
42
40
  body.strip.empty?
43
41
  end
44
- memoize :no_content?
45
42
 
46
43
  def raise_error
47
44
  error_class = Callapi::Errors.error_by_status(status)
@@ -10,7 +10,6 @@ class Callapi::Call::Parser::Json < Callapi::Call::Parser
10
10
  def to_hash
11
11
  @to_hash ||= MultiJson.load(body)
12
12
  end
13
- #TODO: remove Memoist
14
13
 
15
14
  def error_message
16
15
  to_hash['error_message'] rescue super
@@ -1,6 +1,4 @@
1
1
  class Callapi::Routes::Metadata
2
- extend Memoist
3
-
4
2
  def initialize(http_method_namespace, *args)
5
3
  @http_method_namespace = http_method_namespace
6
4
  @call_name, @call_options = args.shift.to_s, *args
@@ -37,7 +35,7 @@ class Callapi::Routes::Metadata
37
35
  end
38
36
 
39
37
  def call_name_with_namespaces
40
- namespaces.push(@call_name).map do |class_name|
38
+ @call_name_with_namespaces ||= namespaces.push(@call_name).map do |class_name|
41
39
  class_name = if class_name_with_param_key?(class_name)
42
40
  class_name_to_class_name_with_param_key(class_name)
43
41
  else
@@ -46,17 +44,15 @@ class Callapi::Routes::Metadata
46
44
  SuperString.camelize(class_name)
47
45
  end
48
46
  end
49
- memoize :call_name_with_namespaces
50
47
 
51
48
  def call_name_with_all_namespaces
52
- [@http_method_namespace.to_s] + call_name_with_namespaces
49
+ @call_name_with_all_namespaces ||=
50
+ [@http_method_namespace.to_s] + call_name_with_namespaces
53
51
  end
54
- memoize :call_name_with_all_namespaces
55
52
 
56
53
  def namespaces
57
- Callapi::Routes.send(:namespaces).dup
54
+ @namespaces ||= Callapi::Routes.send(:namespaces).dup
58
55
  end
59
- memoize :namespaces
60
56
 
61
57
  def class_name_with_param_key?(class_name)
62
58
  class_name[0] == ':' || class_name.match('/:')
@@ -1,3 +1,3 @@
1
1
  module Callapi
2
- VERSION = '0.9.0'
2
+ VERSION = '0.9.1'
3
3
  end
@@ -1,3 +1,5 @@
1
+ require 'ostruct'
2
+
1
3
  class DeepStruct < OpenStruct
2
4
  def initialize(hash = nil)
3
5
  @table = {}
@@ -15,17 +15,17 @@ describe Callapi::Call::Parser do
15
15
 
16
16
  it 'should not parse response twice unless call is reloaded' do
17
17
  cached_response = {'json' => true}
18
- expect(@call.response.data).to eql cached_response
18
+ expect(@call.data).to eql cached_response
19
19
  @call.response_parser = Callapi::Call::Parser::Plain
20
- expect(@call.response.data).to eql cached_response
20
+ expect(@call.data).to eql cached_response
21
21
  @call.reload
22
- expect(@call.response.data).to eql '{"json": true}'
22
+ expect(@call.data).to eql '{"json": true}'
23
23
  end
24
24
 
25
25
  end
26
26
 
27
27
  context '#data' do
28
- subject { @call.response.data }
28
+ subject { @call.data }
29
29
 
30
30
  context 'when API returned 5xx' do
31
31
  before do
@@ -56,6 +56,5 @@ describe Callapi::Call::Parser do
56
56
  expect{ subject }.to raise_error { Callapi::NotAuthorizedError }
57
57
  end
58
58
  end
59
-
60
59
  end
61
60
  end
@@ -5,8 +5,8 @@ describe Callapi::Routes do
5
5
  described_class.draw do
6
6
  get 'version'
7
7
  post 'version'
8
- put 'version'
9
- delete 'version'
8
+ put :version
9
+ delete :version
10
10
  patch :version
11
11
 
12
12
  get 'users', strategy: Callapi::Call::Request::Mock, parser: Callapi::Call::Parser::Plain
@@ -18,6 +18,9 @@ describe Callapi::Routes do
18
18
  get 'index'
19
19
  end
20
20
  end
21
+
22
+ get 'orders/:id'
23
+ get 'orders'
21
24
  end
22
25
  end
23
26
 
@@ -120,4 +123,26 @@ describe Callapi::Routes do
120
123
  expect( Callapi::Get::Users::IdParam::Posts::PostIdParam::Details.superclass ).to eql(Callapi::Call::Base)
121
124
  end
122
125
  end
126
+
127
+ context '#get("orders/:id") and get("orders") in this direct order' do
128
+ context '#get "orders/:id"' do
129
+ it 'should create Callapi::Get::Orders::IdParam class' do
130
+ expect( Callapi::Get::Orders::IdParam.superclass ).to eql(Callapi::Call::Base)
131
+ end
132
+
133
+ it 'should create #get_orders_by_id method' do
134
+ expect( get_orders_by_id_call ).to be_instance_of(Callapi::Get::Orders::IdParam)
135
+ end
136
+ end
137
+
138
+ context '#get "orders"' do
139
+ it 'should create Callapi::Get::Orders class' do
140
+ expect( Callapi::Get::Orders.superclass ).to eql(Callapi::Call::Base)
141
+ end
142
+
143
+ it 'should create #get_orders method' do
144
+ expect( get_orders_call ).to be_instance_of(Callapi::Get::Orders)
145
+ end
146
+ end
147
+ end
123
148
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: callapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kacper Walanus
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-18 00:00:00.000000000 Z
11
+ date: 2015-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,20 +108,6 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: 0.0.5
111
- - !ruby/object:Gem::Dependency
112
- name: memoist
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - "~>"
116
- - !ruby/object:Gem::Version
117
- version: '0.11'
118
- type: :runtime
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - "~>"
123
- - !ruby/object:Gem::Version
124
- version: '0.11'
125
111
  description: Easy API calls
126
112
  email:
127
113
  - kacper@walanus.com