likeno 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.rdoc +9 -1
- data/README.md +0 -4
- data/lib/likeno/entity.rb +9 -5
- data/lib/likeno/helpers/crud_request_parameters.rb +28 -0
- data/lib/likeno/request_methods.rb +3 -1
- data/lib/likeno/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3381fbdae77e9d212af70d6141ef95a0593ddc08
|
4
|
+
data.tar.gz: a060ca71aed718e4c73c9d4a29c6b9ed42666414
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94cab682b8730e50c895acb5d89805a6e4b8771306e110818ff096ab1a7e398468b6ce2c833f070e7eb350808d573b8a37dc77884d4f28bb9cba0c957e750644
|
7
|
+
data.tar.gz: f29f24e6fe824a937b0e1332fb2430334ca40aeb4c19b4e32e5e389ac79d629108468ba21509fc85b20cf8f1501d62fc08c542890c7f684b6685600eccf16236
|
data/CHANGELOG.rdoc
CHANGED
@@ -2,7 +2,15 @@
|
|
2
2
|
|
3
3
|
Likeno is a library for remote data model access over HTTP
|
4
4
|
|
5
|
-
==
|
5
|
+
== Unreleased
|
6
|
+
|
7
|
+
== v1.0.0 - 23/03/2016
|
8
|
+
|
9
|
+
* Add support for custom headers for requests
|
10
|
+
* Add prefixing support on exists and find methods
|
11
|
+
* Add new listing method all
|
12
|
+
|
13
|
+
== v0.0.1 - 21/03/2016
|
6
14
|
|
7
15
|
Imported from KalibroClient (http://github.com/mezuro/kalibro_client)
|
8
16
|
|
data/README.md
CHANGED
data/lib/likeno/entity.rb
CHANGED
@@ -54,7 +54,7 @@ module Likeno
|
|
54
54
|
update
|
55
55
|
else
|
56
56
|
without_request_error? do
|
57
|
-
response = self.class.request(save_action, save_params, :post, save_prefix)
|
57
|
+
response = self.class.request(save_action, save_params, :post, save_prefix, save_headers)
|
58
58
|
|
59
59
|
self.id = response[instance_entity_name]["id"]
|
60
60
|
self.created_at = response[instance_entity_name]["created_at"] unless response[instance_entity_name]["created_at"].nil?
|
@@ -78,7 +78,7 @@ module Likeno
|
|
78
78
|
def update(attributes = {})
|
79
79
|
attributes.each { |field, value| send("#{field}=", value) if self.class.valid?(field) }
|
80
80
|
without_request_error? do
|
81
|
-
self.class.request(update_action, update_params, :put, update_prefix)
|
81
|
+
self.class.request(update_action, update_params, :put, update_prefix, update_headers)
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
@@ -92,17 +92,21 @@ module Likeno
|
|
92
92
|
end
|
93
93
|
|
94
94
|
def self.exists?(id)
|
95
|
-
request(exists_action, id_params(id), :get)['exists']
|
95
|
+
request(exists_action, id_params(id), :get, exists_prefix, exists_headers)['exists']
|
96
96
|
end
|
97
97
|
|
98
98
|
def self.find(id)
|
99
|
-
response = request(find_action, id_params(id), :get)
|
99
|
+
response = request(find_action, id_params(id), :get, find_prefix, find_headers)
|
100
100
|
new(response[entity_name], true)
|
101
101
|
end
|
102
102
|
|
103
|
+
def self.all
|
104
|
+
create_objects_array_from_hash request(all_action, all_params, :get, all_prefix, all_headers)
|
105
|
+
end
|
106
|
+
|
103
107
|
def destroy
|
104
108
|
without_request_error? do
|
105
|
-
response = self.class.request(destroy_action, destroy_params, :delete, destroy_prefix)
|
109
|
+
response = self.class.request(destroy_action, destroy_params, :delete, destroy_prefix, destroy_headers)
|
106
110
|
@persisted = false
|
107
111
|
end
|
108
112
|
end
|
@@ -48,6 +48,13 @@ module Likeno
|
|
48
48
|
''
|
49
49
|
end
|
50
50
|
|
51
|
+
def default_headers
|
52
|
+
{}
|
53
|
+
end
|
54
|
+
alias_method :save_headers, :default_headers
|
55
|
+
alias_method :destroy_headers, :default_headers
|
56
|
+
alias_method :update_headers, :default_headers
|
57
|
+
|
51
58
|
module ClassMethods
|
52
59
|
def exists_action
|
53
60
|
':id/exists'
|
@@ -60,6 +67,27 @@ module Likeno
|
|
60
67
|
def find_action
|
61
68
|
':id'
|
62
69
|
end
|
70
|
+
|
71
|
+
def all_action
|
72
|
+
''
|
73
|
+
end
|
74
|
+
|
75
|
+
def all_params
|
76
|
+
{}
|
77
|
+
end
|
78
|
+
|
79
|
+
def find_prefix
|
80
|
+
''
|
81
|
+
end
|
82
|
+
alias_method :exists_prefix, :find_prefix
|
83
|
+
alias_method :all_prefix, :find_prefix
|
84
|
+
|
85
|
+
def default_headers
|
86
|
+
{}
|
87
|
+
end
|
88
|
+
alias_method :find_headers, :default_headers
|
89
|
+
alias_method :exists_headers, :default_headers
|
90
|
+
alias_method :all_headers, :default_headers
|
63
91
|
end
|
64
92
|
end
|
65
93
|
end
|
@@ -19,7 +19,7 @@ require 'likeno/errors'
|
|
19
19
|
|
20
20
|
module Likeno
|
21
21
|
module RequestMethods
|
22
|
-
def request(action, params = {}, method = :post, prefix = '')
|
22
|
+
def request(action, params = {}, method = :post, prefix = '', headers = {})
|
23
23
|
response = client.send(method) do |request|
|
24
24
|
url = "/#{endpoint}/#{action}".gsub(':id', params[:id].to_s)
|
25
25
|
url = "/#{prefix}#{url}" unless prefix.empty?
|
@@ -27,6 +27,8 @@ module Likeno
|
|
27
27
|
request.body = params unless method == :get || params.empty?
|
28
28
|
request.options.timeout = 300
|
29
29
|
request.options.open_timeout = 300
|
30
|
+
|
31
|
+
headers.each { |(key, value)| request.headers[key] = value }
|
30
32
|
end
|
31
33
|
|
32
34
|
if response.success?
|
data/lib/likeno/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: likeno
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Heitor Reis
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-03-
|
13
|
+
date: 2016-03-23 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|