restfolia 1.0.2 → 1.0.3

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.
data/Changelog.md CHANGED
@@ -1,11 +1,11 @@
1
1
  # Restfolia Changelog
2
2
 
3
- ## 1.0.2 / edge
3
+ ## 1.0.2 / 2012-06-22
4
4
 
5
5
  * \+ [Resource Creator supports Json - Array](https://github.com/rogerleite/restfolia/commit/363b00abf379a2849790ed4be86b9085bddbd2af)
6
6
  * \+ [Support to multiple levels of hash on ResourceCreator](https://github.com/rogerleite/restfolia/commit/aa1e96a82f9b34a9415e46066874e35dfb7a1dbd)
7
7
  * ! [Fix bug on not supporting id attribute on resource](https://github.com/rogerleite/restfolia/issues/5)
8
- * \+ [Support http basic authentication](https://github.com/rogerleite/restfolia/commit/372aa40b9b2f4df35b7c30ed70534fc99e3b3233)
8
+ * \+ [Support http basic authentication](https://github.com/rogerleite/restfolia/commit/372aa40b9b2f4df35b7c30ed70534fc99e3b3233) (Willian Fernandes)
9
9
 
10
10
  ## 1.0.1 / 2012-05-28
11
11
 
@@ -91,7 +91,7 @@ module Restfolia
91
91
  # Restfolia::HTTP::Behaviour methods for more details.
92
92
  # Raises URI::InvalidURIError if url attribute is invalid.
93
93
  def post(params)
94
- body = MultiJson.dump(params)
94
+ body = MultiJson.encode(params)
95
95
 
96
96
  args = self.configuration.merge(:body => body)
97
97
  http_resp = Restfolia::HTTP::Request.do_request(:post, self.url, args)
@@ -118,7 +118,7 @@ module Restfolia
118
118
  # Restfolia::HTTP::Behaviour methods for more details.
119
119
  # Raises URI::InvalidURIError if url attribute is invalid.
120
120
  def put(params)
121
- body = MultiJson.dump(params)
121
+ body = MultiJson.encode(params)
122
122
 
123
123
  args = self.configuration.merge(:body => body)
124
124
  http_resp = Restfolia::HTTP::Request.do_request(:put, self.url, args)
@@ -28,7 +28,7 @@ module Restfolia::HTTP
28
28
  def parse_json(http_response)
29
29
  body = http_response.body
30
30
  begin
31
- MultiJson.load(body, :symbolize_keys => true)
31
+ MultiJson.decode(body, :symbolize_keys => true)
32
32
  rescue MultiJson::DecodeError => ex
33
33
  msg = "Body should be a valid json. #{ex.message}"
34
34
  raise Restfolia::ResponseError.new(msg, caller, http_response)
@@ -56,7 +56,7 @@ module Restfolia
56
56
  #Add json keys as methods of Resource
57
57
  #http://blog.jayfields.com/2008/02/ruby-replace-methodmissing-with-dynamic.html
58
58
  @_json.each do |method, value|
59
- next if self.respond_to?(method) && (method != :id)
59
+ next if self.respond_to?(method) && (method != :id) && (method != "id")
60
60
 
61
61
  (class << self; self; end).class_eval do
62
62
  define_method(method) do |*args|
@@ -91,16 +91,16 @@ module Restfolia
91
91
  # Returns Array of EntryPoints or Empty Array if :links not exist.
92
92
  # Raises RuntimeError if link doesn't have :href and :rel keys.
93
93
  def parse_links(json)
94
- links = json[:links] || json[:link]
94
+ links = json[:links] || json[:link] || json['links'] || json['link']
95
95
  return [] if links.nil?
96
96
 
97
97
  links = [links] unless links.is_a?(Array)
98
98
  links.map do |link|
99
- if link[:href].nil? || link[:rel].nil?
99
+ if (link[:href].nil? && link['href'].nil?) || (link[:rel].nil? && link['rel'].nil?)
100
100
  msg = "Invalid hash link: #{link.inspect}"
101
101
  raise(RuntimeError, msg, caller)
102
102
  end
103
- EntryPoint.new(link[:href], link[:rel])
103
+ EntryPoint.new(link[:href] || link['href'], link[:rel] || link['rel'])
104
104
  end
105
105
  end
106
106
 
@@ -108,7 +108,7 @@ module Restfolia
108
108
  #
109
109
  # Returns attributes to be ignored when creating Resource.
110
110
  def attributes_to_dont_parse
111
- [:links, :link].freeze
111
+ [:links, :link, 'links', 'link'].freeze
112
112
  end
113
113
 
114
114
  # Internal: Check if value is eligible to become a Restfolia::Resource.
@@ -1,3 +1,3 @@
1
1
  module Restfolia
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
data/restfolia.gemspec CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
21
 
22
- s.add_runtime_dependency "multi_json", "~> 1.3.0"
22
+ s.add_runtime_dependency "multi_json", "~> 1.0"
23
23
 
24
24
  s.add_development_dependency "rake"
25
25
  s.add_development_dependency "minitest", "~> 3"
@@ -22,6 +22,11 @@ describe Restfolia::ResourceCreator do
22
22
  resource.must_be_instance_of(OpenStruct)
23
23
  end
24
24
 
25
+ it "don't transforms nested link hash in Resource" do
26
+ resource = subject.create('link' => {:rel => "nested",:href => "http://localhost"})
27
+ resource.link.must_be_instance_of(Hash)
28
+ end
29
+
25
30
  it "transforms nested hash in Resource" do
26
31
  resource = subject.create(:attr_test => {:nested => "nested"})
27
32
  resource.attr_test.must_be_instance_of(OpenStruct)
@@ -66,6 +66,18 @@ describe Restfolia::Resource do
66
66
  resource.links[0].must_be_instance_of(Restfolia::EntryPoint)
67
67
  end
68
68
 
69
+ it "understand 'links' as string hash key" do
70
+ resource = subject.new('links' => array_links)
71
+ resource.links.must_be_instance_of(Array)
72
+ resource.links[0].must_be_instance_of(Restfolia::EntryPoint)
73
+ end
74
+
75
+ it "understand 'link' as string hash key" do
76
+ resource = subject.new('link' => array_links)
77
+ resource.links.must_be_instance_of(Array)
78
+ resource.links[0].must_be_instance_of(Restfolia::EntryPoint)
79
+ end
80
+
69
81
  it "raises Error for invalid link" do
70
82
  resource = subject.new(:links => {:invalid => "invalid"})
71
83
  lambda { resource.links }.must_raise(RuntimeError)
@@ -88,6 +100,11 @@ describe Restfolia::Resource do
88
100
  resource.links("rel2").must_be_instance_of(Restfolia::EntryPoint)
89
101
  end
90
102
 
103
+ it "returns EntryPoint even when hash key is string" do
104
+ resource = subject.new('link' => {'rel' => 'rel2', 'href' => 'http://localhost/'})
105
+ resource.links("rel2").must_be_instance_of(Restfolia::EntryPoint)
106
+ end
107
+
91
108
  end
92
109
 
93
110
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restfolia
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 2
10
- version: 1.0.2
9
+ - 3
10
+ version: 1.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Roger Leite
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-06-22 00:00:00 Z
18
+ date: 2012-07-04 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: multi_json
@@ -25,12 +25,11 @@ dependencies:
25
25
  requirements:
26
26
  - - ~>
27
27
  - !ruby/object:Gem::Version
28
- hash: 27
28
+ hash: 15
29
29
  segments:
30
30
  - 1
31
- - 3
32
31
  - 0
33
- version: 1.3.0
32
+ version: "1.0"
34
33
  type: :runtime
35
34
  version_requirements: *id001
36
35
  - !ruby/object:Gem::Dependency