callapi 0.8.3 → 0.9.0
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 +4 -4
- data/CHANGELOG.md +26 -0
- data/Gemfile +0 -1
- data/README.md +7 -8
- data/callapi.gemspec +0 -1
- data/lib/callapi.rb +1 -0
- data/lib/callapi/call/request/api.rb +1 -1
- data/lib/callapi/call/request_metadata.rb +1 -3
- data/lib/callapi/config.rb +2 -2
- data/lib/callapi/errors.rb +1 -1
- data/lib/callapi/routes.rb +15 -22
- data/lib/callapi/routes/helper_method_creator.rb +28 -0
- data/lib/callapi/routes/metadata.rb +4 -3
- data/lib/callapi/version.rb +1 -1
- data/lib/ext/super_string.rb +19 -0
- data/spec/unit/routes_spec.rb +1 -1
- metadata +5 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 666cfc16f86f8bbab5db5e2fbc10b15622111406
|
4
|
+
data.tar.gz: b9e3dec2a83fad0d45a6913b7c2b323bf5c0a1e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7f45e5636ed00b419e69bbeacca4dedea65bca9b0c859d6279fbb9656c47e16e047c8c38e53b3e816d1f04c49ce108e22c5e0f4ae8c8048eb258213ca1749c3
|
7
|
+
data.tar.gz: 86bb3292da0e5732199721b23b98d35aca92e6b0278636434d0444077b344f2504f70eed282ca6ca2b8db88261fbdf3b0722dc7a0a5cb6952d122d4f6077ccf2
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
## 0.8.4 (next release)
|
2
|
+
|
3
|
+
- Remove activesupport dependency
|
4
|
+
- URI pattern can be a `Symbol` (before only `String`s were accepted)
|
5
|
+
- Bugfix: #1
|
6
|
+
- Backward compatibility fix for `#api_path_prefix`
|
7
|
+
- Changelog added
|
8
|
+
|
9
|
+
## 0.8.3
|
10
|
+
|
11
|
+
- API path prefix taken from `Config.api_host` (no need to set `Config.api_path_prefix`)
|
12
|
+
- Added Ruby dependency (>= 2.0)
|
13
|
+
- Code Climate refactor
|
14
|
+
|
15
|
+
## 0.8.2
|
16
|
+
|
17
|
+
- Bugfix: Critical issue fix (undefined method `#api_path_prefix`)
|
18
|
+
|
19
|
+
## 0.8.1
|
20
|
+
|
21
|
+
- Dependencies
|
22
|
+
- Documentation update
|
23
|
+
|
24
|
+
## 0.8
|
25
|
+
|
26
|
+
- Initial release, after long internal usage
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -29,7 +29,7 @@ Or install it yourself as:
|
|
29
29
|
require 'callapi'
|
30
30
|
|
31
31
|
Callapi::Config.configure do |config|
|
32
|
-
config.api_host = 'http://
|
32
|
+
config.api_host = 'http://your.api.org/v2'
|
33
33
|
end
|
34
34
|
```
|
35
35
|
|
@@ -53,7 +53,10 @@ get_notes_call.response.data #=> [{"id"=>1, "title"=>"Jogging in park"}, {"id
|
|
53
53
|
get_notes_call.response.body #=> '[{"id":1,"title":"Jogging in park"},{"id":2,"title":"Pick-up posters from post-office"}]'
|
54
54
|
|
55
55
|
# Request with params:
|
56
|
-
post_notes_call(
|
56
|
+
post_notes_call(id: 1, title: "Swimming").response.data
|
57
|
+
|
58
|
+
# Request with params and headers:
|
59
|
+
post_notes_call(id: 1, title: "Swimming").add_headers('X-SECRET-TOKEN' => '783hdkfds349').response.data
|
57
60
|
```
|
58
61
|
|
59
62
|
<br>
|
@@ -174,17 +177,13 @@ call.with_response_parser(Callapi::Call::Parser::Plain).response.data
|
|
174
177
|
##### Config options
|
175
178
|
|
176
179
|
- `api_host`
|
177
|
-
- `api_path_prefix`
|
178
180
|
- `default_response_parser`
|
179
181
|
- `log_level`
|
180
182
|
|
181
183
|
```ruby
|
182
184
|
Callapi::Config.configure do |config|
|
183
|
-
config.api_host = 'http://your.api.org'
|
184
|
-
|
185
|
-
# request will be send to http://your.api.org/api/
|
186
|
-
config.api_path_prefix = 'api'
|
187
|
-
|
185
|
+
config.api_host = 'http://your.api.org/v2'
|
186
|
+
|
188
187
|
# see Parsers section
|
189
188
|
config.default_response_parser = Callapi::Call::Parser::Json::AsObject
|
190
189
|
|
data/callapi.gemspec
CHANGED
@@ -26,7 +26,6 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_runtime_dependency 'addressabler', '~> 0.1'
|
27
27
|
spec.add_runtime_dependency 'multi_json', '~> 1.10'
|
28
28
|
spec.add_runtime_dependency 'colorize', '~> 0.7'
|
29
|
-
spec.add_runtime_dependency 'activesupport', '~> 4.2'
|
30
29
|
spec.add_runtime_dependency 'chainy', '~> 0.0.5'
|
31
30
|
spec.add_runtime_dependency 'memoist', '~> 0.11'
|
32
31
|
|
data/lib/callapi.rb
CHANGED
@@ -10,7 +10,7 @@ class Callapi::Call::Request::Api < Callapi::Call::Request::Http
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def api_path_prefix
|
13
|
-
Callapi::Config.api_path_prefix if Callapi::Config.api_path_prefix # backward compatibility
|
13
|
+
return Callapi::Config.api_path_prefix if Callapi::Config.api_path_prefix # backward compatibility
|
14
14
|
URI(Callapi::Config.api_host).path
|
15
15
|
end
|
16
16
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'active_support/core_ext/string/inflections'
|
2
|
-
|
3
1
|
class Callapi::Call::RequestMetadata < Struct.new(:context)
|
4
2
|
extend Memoist
|
5
3
|
|
@@ -28,7 +26,7 @@ class Callapi::Call::RequestMetadata < Struct.new(:context)
|
|
28
26
|
end
|
29
27
|
|
30
28
|
def request_path_without_replaced_param_keys
|
31
|
-
'/' +
|
29
|
+
'/' + SuperString.underscore(call_name)
|
32
30
|
end
|
33
31
|
memoize :request_path_without_replaced_param_keys
|
34
32
|
|
data/lib/callapi/config.rb
CHANGED
@@ -14,7 +14,7 @@ class Callapi::Config
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def default_request_strategy
|
17
|
-
@default_request_strategy ||= DEFAULT_REQUEST_STRATEGY
|
17
|
+
@default_request_strategy ||= Kernel.const_get DEFAULT_REQUEST_STRATEGY
|
18
18
|
end
|
19
19
|
|
20
20
|
def api_path_prefix
|
@@ -22,7 +22,7 @@ class Callapi::Config
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def default_response_parser
|
25
|
-
@default_response_parser ||= DEFAULT_RESPONSE_PARSER
|
25
|
+
@default_response_parser ||= Kernel.const_get DEFAULT_RESPONSE_PARSER
|
26
26
|
end
|
27
27
|
|
28
28
|
def mocks_directory=(mocks_directory)
|
data/lib/callapi/errors.rb
CHANGED
data/lib/callapi/routes.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
require 'active_support/core_ext/string'
|
2
|
-
|
3
1
|
class Callapi::Routes
|
4
2
|
require_relative 'routes/metadata'
|
3
|
+
require_relative 'routes/helper_method_creator'
|
5
4
|
|
6
5
|
class << self
|
7
6
|
def draw(&block)
|
@@ -10,6 +9,7 @@ class Callapi::Routes
|
|
10
9
|
instance_eval &block
|
11
10
|
|
12
11
|
create_classes
|
12
|
+
create_helper_methods
|
13
13
|
end
|
14
14
|
|
15
15
|
def get(*args)
|
@@ -52,7 +52,9 @@ class Callapi::Routes
|
|
52
52
|
if namespace.constants.include?(class_name.to_sym)
|
53
53
|
namespace.const_get(class_name)
|
54
54
|
else
|
55
|
-
create_class(namespace, class_name, class_metadata)
|
55
|
+
create_class(namespace, class_name, class_metadata).tap do |klass|
|
56
|
+
created_call_classes << klass
|
57
|
+
end
|
56
58
|
end
|
57
59
|
end
|
58
60
|
end
|
@@ -75,7 +77,6 @@ class Callapi::Routes
|
|
75
77
|
def create_call_class(namespace, class_name, class_metadata)
|
76
78
|
namespace.const_set(class_name, Class.new(Callapi::Call::Base)).tap do |klass|
|
77
79
|
set_call_class_options(klass, class_metadata.class_options) if class_metadata.class_options
|
78
|
-
create_helper_method(klass, class_metadata)
|
79
80
|
end
|
80
81
|
end
|
81
82
|
|
@@ -83,25 +84,12 @@ class Callapi::Routes
|
|
83
84
|
namespace.const_set(new_namespace, Class.new)
|
84
85
|
end
|
85
86
|
|
86
|
-
def
|
87
|
-
|
88
|
-
klass.new(*args)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def helper_method_base_name(class_metadata)
|
93
|
-
class_metadata.call_name_with_namespaces.map do |class_name|
|
94
|
-
class_name.scan(/(::)?((\w)+)Param/).map { |matched_groups| matched_groups[1] }.compact.each do |pattern|
|
95
|
-
class_name.sub!(pattern, "By#{pattern}")
|
96
|
-
class_name.sub!('Param', '')
|
97
|
-
end
|
98
|
-
class_name
|
99
|
-
end
|
87
|
+
def create_helper_methods
|
88
|
+
created_call_classes.each(&method(:create_helper_method))
|
100
89
|
end
|
101
90
|
|
102
|
-
def
|
103
|
-
|
104
|
-
method_name.underscore.gsub('/', '_')
|
91
|
+
def create_helper_method(klass)
|
92
|
+
Callapi::Routes::HelperMethodCreator.new(klass).create
|
105
93
|
end
|
106
94
|
|
107
95
|
def set_call_class_options(klass, options)
|
@@ -123,7 +111,8 @@ class Callapi::Routes
|
|
123
111
|
|
124
112
|
def build_http_method_namespaces
|
125
113
|
@build_http_method_namespaces ||= http_methods.each do |http_method|
|
126
|
-
|
114
|
+
camelized_http_method = SuperString.camelize(http_method.to_s)
|
115
|
+
Callapi.const_set(camelized_http_method, Module.new)
|
127
116
|
end
|
128
117
|
end
|
129
118
|
|
@@ -148,5 +137,9 @@ class Callapi::Routes
|
|
148
137
|
def call_classes_names
|
149
138
|
@call_classes_names ||= call_classes_metadata.map(&:class_name).uniq
|
150
139
|
end
|
140
|
+
|
141
|
+
def created_call_classes
|
142
|
+
@created_call_classes ||= []
|
143
|
+
end
|
151
144
|
end
|
152
145
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class Callapi::Routes::HelperMethodCreator
|
2
|
+
POSTFIX = '_call'
|
3
|
+
|
4
|
+
def initialize(call_class)
|
5
|
+
@call_class = call_class
|
6
|
+
@call_class_name = call_class.to_s
|
7
|
+
end
|
8
|
+
|
9
|
+
def create
|
10
|
+
call_class = @call_class
|
11
|
+
Object.send(:define_method, helper_method_name) do |*args|
|
12
|
+
call_class.new(*args)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def helper_method_base_name
|
17
|
+
class_name = @call_class_name.dup
|
18
|
+
class_name.scan(/(::)?((\w)+)Param/).map { |matched_groups| matched_groups[1] }.compact.each do |pattern|
|
19
|
+
class_name.sub!(pattern, "By#{pattern}")
|
20
|
+
class_name.sub!('Param', '')
|
21
|
+
end
|
22
|
+
class_name
|
23
|
+
end
|
24
|
+
|
25
|
+
def helper_method_name
|
26
|
+
SuperString.underscore(helper_method_base_name).gsub('/', '_').gsub('callapi_', '') + POSTFIX
|
27
|
+
end
|
28
|
+
end
|
@@ -3,7 +3,7 @@ class Callapi::Routes::Metadata
|
|
3
3
|
|
4
4
|
def initialize(http_method_namespace, *args)
|
5
5
|
@http_method_namespace = http_method_namespace
|
6
|
-
@call_name, @call_options = args.shift, *args
|
6
|
+
@call_name, @call_options = args.shift.to_s, *args
|
7
7
|
|
8
8
|
call_name_with_all_namespaces.size.times do |i|
|
9
9
|
metadata = create_metadata(i)
|
@@ -38,11 +38,12 @@ class Callapi::Routes::Metadata
|
|
38
38
|
|
39
39
|
def call_name_with_namespaces
|
40
40
|
namespaces.push(@call_name).map do |class_name|
|
41
|
-
if class_name_with_param_key?(class_name)
|
41
|
+
class_name = if class_name_with_param_key?(class_name)
|
42
42
|
class_name_to_class_name_with_param_key(class_name)
|
43
43
|
else
|
44
44
|
class_name
|
45
|
-
end
|
45
|
+
end
|
46
|
+
SuperString.camelize(class_name)
|
46
47
|
end
|
47
48
|
end
|
48
49
|
memoize :call_name_with_namespaces
|
data/lib/callapi/version.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
class SuperString
|
2
|
+
class << self
|
3
|
+
def camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
|
4
|
+
if first_letter_in_uppercase
|
5
|
+
lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
|
6
|
+
else
|
7
|
+
lower_case_and_underscored_word.first + camelize(lower_case_and_underscored_word)[1..-1]
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def underscore(string)
|
12
|
+
string.gsub(/::/, '/').
|
13
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
14
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
15
|
+
tr("-", "_").
|
16
|
+
downcase
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/spec/unit/routes_spec.rb
CHANGED
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.
|
4
|
+
version: 0.9.0
|
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-
|
11
|
+
date: 2015-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,20 +94,6 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0.7'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: activesupport
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - "~>"
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '4.2'
|
104
|
-
type: :runtime
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - "~>"
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '4.2'
|
111
97
|
- !ruby/object:Gem::Dependency
|
112
98
|
name: chainy
|
113
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -144,6 +130,7 @@ extensions: []
|
|
144
130
|
extra_rdoc_files: []
|
145
131
|
files:
|
146
132
|
- ".gitignore"
|
133
|
+
- CHANGELOG.md
|
147
134
|
- Gemfile
|
148
135
|
- LICENSE.txt
|
149
136
|
- README.md
|
@@ -166,9 +153,11 @@ files:
|
|
166
153
|
- lib/callapi/config.rb
|
167
154
|
- lib/callapi/errors.rb
|
168
155
|
- lib/callapi/routes.rb
|
156
|
+
- lib/callapi/routes/helper_method_creator.rb
|
169
157
|
- lib/callapi/routes/metadata.rb
|
170
158
|
- lib/callapi/version.rb
|
171
159
|
- lib/ext/deep_struct.rb
|
160
|
+
- lib/ext/super_string.rb
|
172
161
|
- spec/spec_helper.rb
|
173
162
|
- spec/unit/call/base_spec.rb
|
174
163
|
- spec/unit/call/request/api_spec.rb
|