kippt 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,12 @@
1
+ # Changelog
2
+
3
+ ## 1.1 / July 20, 2012
4
+
5
+ Changes in response to feedback from [Matias Korhonen](https://github.com/k33l0r):
6
+
7
+ * When adding new lists/clips the object is updated with data received from the service
8
+ * Collections of lists & clips are Enumberable
9
+
10
+ ## 1.0 / June 17, 2012
11
+
12
+ Initial official release.
data/README.md CHANGED
@@ -73,7 +73,7 @@ Get all the lists:
73
73
 
74
74
  ```ruby
75
75
  client = Kippt::Client.new(username: "vesan", token: "2544d6bfddf5893ec8617")
76
- lists = client.lists # Returns Kippt::ListCollection
76
+ lists = client.lists.all # Returns Kippt::ListCollection
77
77
  ```
78
78
 
79
79
  Get single list:
@@ -89,9 +89,11 @@ list = client.lists[list_id] # Returns Kippt::ListItem
89
89
 
90
90
  ```ruby
91
91
  client = Kippt::Client.new(username: "vesan", token: "2544d6bfddf5893ec8617")
92
- clips = client.clips # Returns Kippt::ClipCollection
92
+ clips = client.clips.all # Returns Kippt::ClipCollection
93
93
  ```
94
94
 
95
+ Both ListCollection and ClipCollection are Enumerable.
96
+
95
97
 
96
98
  ### Pagination
97
99
 
@@ -2,7 +2,7 @@ require "ostruct"
2
2
  require "kippt/resource"
3
3
 
4
4
  class Kippt::Clip
5
- include Resource
5
+ include Kippt::Resource
6
6
 
7
7
  attributes :url_domain, :updated, :is_starred, :title,
8
8
  :url, :notes, :created, :list, :id, :resource_uri
@@ -1,4 +1,6 @@
1
1
  module Kippt::Collection
2
+ include Enumerable
3
+
2
4
  attr_reader :total_count, :limit, :offset
3
5
 
4
6
  def initialize(data, collection_resource = nil)
@@ -5,14 +5,16 @@ module Kippt::CollectionResource
5
5
  collection_class.new(@client.get(base_uri, options).body, self)
6
6
  end
7
7
 
8
- def build
9
- object_class.new({}, self)
8
+ def build(attributes = {})
9
+ object_class.new(attributes, self)
10
10
  end
11
11
 
12
12
  def [](resource_id)
13
13
  object_class.new(@client.get("#{base_uri}/#{resource_id}").body)
14
14
  end
15
15
 
16
+ alias find []
17
+
16
18
  def collection_from_url(url)
17
19
  raise ArgumentError.new("The parameter URL can't be blank") if url.nil? || url == ""
18
20
 
@@ -27,9 +29,11 @@ module Kippt::CollectionResource
27
29
  end
28
30
 
29
31
  save_response = {:success => response.success?}
32
+ save_response[:resource] = response.body
30
33
  if response.body["message"]
31
34
  save_response[:error_message] = response.body["message"]
32
35
  end
36
+
33
37
  save_response
34
38
  end
35
39
 
@@ -1,7 +1,7 @@
1
1
  require "ostruct"
2
2
 
3
3
  class Kippt::List
4
- include Resource
4
+ include Kippt::Resource
5
5
 
6
6
  attributes :id, :rss_url, :updated, :title,
7
7
  :created, :slug, :resource_uri
@@ -1,26 +1,27 @@
1
- module Resource
1
+ module Kippt::Resource
2
2
  def self.included(base)
3
3
  base.instance_eval do
4
4
  extend Forwardable
5
5
  attr_reader :attributes, :errors
6
6
 
7
- def_delegators "self.class", :writable_attribute_names
7
+ def_delegators "self.class", :writable_attribute_names, :attribute_names
8
8
  end
9
9
 
10
10
  base.extend(ClassMethods)
11
11
  end
12
12
 
13
13
  module ClassMethods
14
- attr_reader :writable_attribute_names
14
+ attr_reader :writable_attribute_names, :attribute_names
15
15
 
16
16
  def attributes(*attribs)
17
- def_delegators :attributes, *attribs
17
+ @attribute_names = attribs.map {|attrib| attrib.to_sym }
18
+ def_delegators :attributes, *@attribute_names
18
19
  end
19
20
 
20
21
  def writable_attributes(*attribs)
21
- @writable_attribute_names = attribs
22
+ @writable_attribute_names = attribs.map {|attrib| attrib.to_sym }
22
23
  @writable_attribute_names.freeze
23
- def_delegators :attributes, *(attribs.map {|attrib| attrib.to_s + "=" })
24
+ def_delegators :attributes, *(@writable_attribute_names.map {|attrib| attrib.to_s + "=" })
24
25
  end
25
26
  end
26
27
 
@@ -49,6 +50,13 @@ module Resource
49
50
  response = @collection_resource.save_resource(self)
50
51
  if response[:error_message]
51
52
  errors << response[:error_message]
53
+ else
54
+ if response[:resource]
55
+ updated_attributes = response[:resource].select do |key, _|
56
+ attribute_names.include?(key.to_sym)
57
+ end
58
+ @attributes = OpenStruct.new(updated_attributes)
59
+ end
52
60
  end
53
61
  response[:success]
54
62
  end
@@ -1,3 +1,3 @@
1
1
  module Kippt
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -63,6 +63,12 @@ shared_examples_for "collection resource" do
63
63
  end
64
64
  end
65
65
 
66
+ describe "#find" do
67
+ it "exists" do
68
+ subject.respond_to?(:find).should be_true
69
+ end
70
+ end
71
+
66
72
  describe "#collection_from_url" do
67
73
  it "returns a new collection" do
68
74
  stub_get("/#{base_uri}/?limit=20&offset=20").
@@ -87,10 +93,19 @@ shared_examples_for "collection resource" do
87
93
  it "returns new resource" do
88
94
  subject.build.should be_a(resource_class)
89
95
  end
96
+
97
+ it "accepts parameters" do
98
+ subject.object_class.should_receive(:new).with({:an => "attribute"}, subject)
99
+ subject.build(:an => "attribute")
100
+ end
90
101
  end
91
102
  end
92
103
 
93
104
  shared_examples_for "collection" do
105
+ it "is Enumberable" do
106
+ subject.should be_a(Enumerable)
107
+ end
108
+
94
109
  describe "#total_count" do
95
110
  it "returns total count of resources" do
96
111
  subject.total_count.should eq data["meta"]["total_count"]
@@ -234,6 +249,13 @@ shared_examples_for "resource" do
234
249
  {:success => true})
235
250
  subject.save.should be_true
236
251
  end
252
+
253
+ it "sets the updated attributes received from the server" do
254
+ collection_resource.stub(:save_resource).and_return(
255
+ {:success => true, :resource => {:id => 9999}})
256
+ subject.save
257
+ subject.id.should eq 9999
258
+ end
237
259
  end
238
260
 
239
261
  context "with invalid parameters" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kippt
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-17 00:00:00.000000000 Z
12
+ date: 2012-07-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
16
- requirement: !ruby/object:Gem::Requirement
16
+ requirement: &70143540468320 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,15 +21,10 @@ dependencies:
21
21
  version: 0.7.6
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ~>
28
- - !ruby/object:Gem::Version
29
- version: 0.7.6
24
+ version_requirements: *70143540468320
30
25
  - !ruby/object:Gem::Dependency
31
26
  name: faraday_middleware
32
- requirement: !ruby/object:Gem::Requirement
27
+ requirement: &70143540467520 !ruby/object:Gem::Requirement
33
28
  none: false
34
29
  requirements:
35
30
  - - ~>
@@ -37,15 +32,10 @@ dependencies:
37
32
  version: 0.8.7
38
33
  type: :runtime
39
34
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ~>
44
- - !ruby/object:Gem::Version
45
- version: 0.8.7
35
+ version_requirements: *70143540467520
46
36
  - !ruby/object:Gem::Dependency
47
37
  name: multi_json
48
- requirement: !ruby/object:Gem::Requirement
38
+ requirement: &70143540466360 !ruby/object:Gem::Requirement
49
39
  none: false
50
40
  requirements:
51
41
  - - ~>
@@ -53,15 +43,10 @@ dependencies:
53
43
  version: 1.3.4
54
44
  type: :runtime
55
45
  prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ~>
60
- - !ruby/object:Gem::Version
61
- version: 1.3.4
46
+ version_requirements: *70143540466360
62
47
  - !ruby/object:Gem::Dependency
63
48
  name: rspec
64
- requirement: !ruby/object:Gem::Requirement
49
+ requirement: &70143540465780 !ruby/object:Gem::Requirement
65
50
  none: false
66
51
  requirements:
67
52
  - - ~>
@@ -69,15 +54,10 @@ dependencies:
69
54
  version: 2.9.0
70
55
  type: :development
71
56
  prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ~>
76
- - !ruby/object:Gem::Version
77
- version: 2.9.0
57
+ version_requirements: *70143540465780
78
58
  - !ruby/object:Gem::Dependency
79
59
  name: webmock
80
- requirement: !ruby/object:Gem::Requirement
60
+ requirement: &70143540465120 !ruby/object:Gem::Requirement
81
61
  none: false
82
62
  requirements:
83
63
  - - ~>
@@ -85,15 +65,10 @@ dependencies:
85
65
  version: 1.8.6
86
66
  type: :development
87
67
  prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
- requirements:
91
- - - ~>
92
- - !ruby/object:Gem::Version
93
- version: 1.8.6
68
+ version_requirements: *70143540465120
94
69
  - !ruby/object:Gem::Dependency
95
70
  name: simplecov
96
- requirement: !ruby/object:Gem::Requirement
71
+ requirement: &70143540463960 !ruby/object:Gem::Requirement
97
72
  none: false
98
73
  requirements:
99
74
  - - ~>
@@ -101,12 +76,7 @@ dependencies:
101
76
  version: 0.6.4
102
77
  type: :development
103
78
  prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ~>
108
- - !ruby/object:Gem::Version
109
- version: 0.6.4
79
+ version_requirements: *70143540463960
110
80
  description: Client library for using Kippt.com API
111
81
  email:
112
82
  - vesa@vesavanska.com
@@ -117,6 +87,7 @@ files:
117
87
  - .gitignore
118
88
  - .rspec
119
89
  - .travis.yml
90
+ - CHANGELOG.md
120
91
  - Gemfile
121
92
  - LICENSE
122
93
  - README.md
@@ -172,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
172
143
  version: '0'
173
144
  requirements: []
174
145
  rubyforge_project:
175
- rubygems_version: 1.8.24
146
+ rubygems_version: 1.8.10
176
147
  signing_key:
177
148
  specification_version: 3
178
149
  summary: Client library for using Kippt.com API