likeno 0.0.1 → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5ab176898e75da9879337ab0af58d81ec3cfb0ec
4
- data.tar.gz: f8e4367db3a7c1912b66631ff0c51d00fca58d99
3
+ metadata.gz: 3381fbdae77e9d212af70d6141ef95a0593ddc08
4
+ data.tar.gz: a060ca71aed718e4c73c9d4a29c6b9ed42666414
5
5
  SHA512:
6
- metadata.gz: 58c95d5df4c84165c6fa070f2201dd129c3bd3760b71cd95861254506ee1964300ce09ae1ab3b95f7dd57af8c2f57c27142b91f137e15c561ca5d1abc3d4b93a
7
- data.tar.gz: 9fd72126846830c0aa96753f79d4f1f4a0c04c04f6b3693bc19d4f08e9dad9882c9fac4a91c16b5ef50c1c18019e3a6d5d3d0f40f30cad3a9d20afe2cb8d8350
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
- == v0.0.1 (Initial version)
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
@@ -69,7 +69,3 @@ end
69
69
  ```
70
70
 
71
71
  It returns a `hash` with the response body.
72
-
73
- ## Versioning
74
-
75
- Kolekti follows the [semantic versioning](http://semver.org/) policy.
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?
@@ -14,5 +14,5 @@
14
14
  # along with Likeno. If not, see <http://www.gnu.org/licenses/>.
15
15
 
16
16
  module Likeno
17
- VERSION = '0.0.1'
17
+ VERSION = '1.0.0'
18
18
  end
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.1
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-21 00:00:00.000000000 Z
13
+ date: 2016-03-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler