grape-client 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/grape_client/base.rb +13 -10
- data/lib/grape_client/collection.rb +8 -0
- data/lib/grape_client/connection.rb +1 -1
- data/lib/grape_client/has_many.rb +1 -1
- data/lib/grape_client/rest_methods_collection.rb +1 -0
- data/lib/grape_client/rest_methods_member.rb +8 -7
- data/lib/grape_client/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 341b46f253dfcb759fe23752366c38f6ae202f8b
|
4
|
+
data.tar.gz: fff3c514bc2727305905d86b6f866c9671eaef03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82f1698dc7ec49188fa943a0a11edd14ccefaccd5022fd0af67c891bdb8a53b44eb7798ec4a184540f7ecdf5ca648a0d5c5046d79e84b13def2fa07ae495be97
|
7
|
+
data.tar.gz: 0a111811d89accbd8104ca14b8a2dd128af5ff032cf18fe7e89d7ad3f0b075813b371f834c4753a6fe17dd573b11139e3d3a31546195c3fac292b7de5f4ad1e6
|
data/README.md
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
# GrapeClient
|
2
|
+
[![GitHub version](https://badge.fury.io/gh/desofto%2Fgrape-client.svg)](https://badge.fury.io/gh/desofto%2Fgrape-client)
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/grape-client.svg)](https://badge.fury.io/rb/grape-client)
|
2
4
|
[![Build Status](https://travis-ci.org/desofto/grape-client.svg?branch=master)](https://travis-ci.org/desofto/grape-client)
|
3
5
|
[![Code Climate](https://codeclimate.com/github/desofto/grape-client/badges/gpa.svg)](https://codeclimate.com/github/desofto/grape-client)
|
4
6
|
[![Test Coverage](https://codeclimate.com/github/desofto/grape-client/badges/coverage.svg)](https://codeclimate.com/github/desofto/grape-client/coverage)
|
data/lib/grape_client/base.rb
CHANGED
@@ -9,15 +9,15 @@ module GrapeClient
|
|
9
9
|
include BelongsTo
|
10
10
|
include HasMany
|
11
11
|
|
12
|
-
|
12
|
+
attr_reader :attributes
|
13
13
|
attr_accessor :site, :user, :password, :prefix
|
14
14
|
|
15
15
|
def inherited(child)
|
16
|
-
child.attributes
|
17
|
-
child.site
|
18
|
-
child.user
|
19
|
-
child.password
|
20
|
-
child.prefix
|
16
|
+
child.instance_variable_set('@attributes', attributes.try(:dup) || [])
|
17
|
+
child.instance_variable_set('@site', GrapeClient.configuration.site)
|
18
|
+
child.instance_variable_set('@user', GrapeClient.configuration.user)
|
19
|
+
child.instance_variable_set('@password', GrapeClient.configuration.password)
|
20
|
+
child.instance_variable_set('@prefix', GrapeClient.configuration.prefix)
|
21
21
|
end
|
22
22
|
|
23
23
|
def attr_accessor(*names)
|
@@ -79,15 +79,18 @@ module GrapeClient
|
|
79
79
|
end
|
80
80
|
|
81
81
|
def respond_to?(method_name, *args, &block)
|
82
|
-
|
83
|
-
|
84
|
-
|
82
|
+
super ||
|
83
|
+
begin
|
84
|
+
name = method_name.to_s
|
85
|
+
name = name[0..-2] if name.last == '='
|
86
|
+
self.class.attributes.include?(name.to_sym)
|
87
|
+
end
|
85
88
|
end
|
86
89
|
|
87
90
|
def to_post
|
88
|
-
entity_name = self.class.entity_name
|
89
91
|
list = self.class.attributes
|
90
92
|
filtered_attributes = attributes.select { |key, _value| list.include? key }
|
93
|
+
entity_name = self.class.entity_name
|
91
94
|
filtered_attributes.transform_keys { |key| "#{entity_name}[#{key}]" }
|
92
95
|
end
|
93
96
|
|
@@ -50,8 +50,8 @@ module GrapeClient
|
|
50
50
|
def validate_response(res)
|
51
51
|
case res
|
52
52
|
when Net::HTTPUnauthorized then raise Unauthorized
|
53
|
-
when Net::HTTPSuccess then res.body
|
54
53
|
when Net::HTTPUnprocessableEntity then raise InvalidEntity
|
54
|
+
when Net::HTTPSuccess then res.body
|
55
55
|
else raise UnknownError, res.body
|
56
56
|
end
|
57
57
|
end
|
@@ -5,7 +5,7 @@ module GrapeClient
|
|
5
5
|
clazz = class_from_name(options[:class_name] || property.to_s.singularize)
|
6
6
|
case @attributes[property]
|
7
7
|
when Collection then @attributes[property]
|
8
|
-
when nil
|
8
|
+
when nil
|
9
9
|
@attributes[property] = clazz.where("#{self.class.entity_name}_id" => id)
|
10
10
|
else
|
11
11
|
@attributes[property].map! do |element|
|
@@ -49,6 +49,7 @@ module GrapeClient
|
|
49
49
|
|
50
50
|
def request(method, url, params = {}, &_block)
|
51
51
|
url = [endpoint, url].compact.join('/')
|
52
|
+
method = method.compact.join('/') if method.is_a? Array
|
52
53
|
response = connection.request method, url, params
|
53
54
|
if block_given?
|
54
55
|
yield response
|
@@ -13,7 +13,7 @@ module GrapeClient
|
|
13
13
|
|
14
14
|
def save
|
15
15
|
save!
|
16
|
-
rescue Connection::InvalidEntity
|
16
|
+
rescue Connection::InvalidEntity, Connection::UnknownError
|
17
17
|
false
|
18
18
|
end
|
19
19
|
|
@@ -32,19 +32,20 @@ module GrapeClient
|
|
32
32
|
|
33
33
|
protected
|
34
34
|
|
35
|
+
def method_with_id(method)
|
36
|
+
[id, method].compact.join('/')
|
37
|
+
end
|
38
|
+
|
35
39
|
def get(method, params = {}, &block)
|
36
|
-
method
|
37
|
-
self.class.send(:get, method, params, &block)
|
40
|
+
self.class.send(:get, method_with_id(method), params, &block)
|
38
41
|
end
|
39
42
|
|
40
43
|
def put(method, params = {}, &block)
|
41
|
-
method
|
42
|
-
self.class.send(:put, method, params, &block)
|
44
|
+
self.class.send(:put, method_with_id(method), params, &block)
|
43
45
|
end
|
44
46
|
|
45
47
|
def post(method, params = {}, &block)
|
46
|
-
method
|
47
|
-
self.class.send(:post, method, params, &block)
|
48
|
+
self.class.send(:post, method_with_id(method), params, &block)
|
48
49
|
end
|
49
50
|
|
50
51
|
def delete(params = {}, &block)
|
data/lib/grape_client/version.rb
CHANGED