pinboard_api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/spec/post_spec.rb ADDED
@@ -0,0 +1,86 @@
1
+ require "spec_helper"
2
+
3
+ describe PinboardApi::Post do
4
+ it "is defined" do
5
+ defined? PinboardApi::Post
6
+ end
7
+
8
+ let(:attributes) do
9
+ {
10
+ "description" => "Test Description",
11
+ "extended" => "Test Extended",
12
+ "hash" => "d58e3582afa99040e27b92b13c8f2280",
13
+ "href" => "www.example.com",
14
+ "tags" => "tag"
15
+ }
16
+ end
17
+
18
+ let(:post) { PinboardApi::Post }
19
+ let(:new_post) { PinboardApi::Post.new }
20
+
21
+ it { new_post.must_respond_to :description }
22
+ it { new_post.must_respond_to :extended }
23
+ it { new_post.must_respond_to :hash }
24
+ it { new_post.must_respond_to :href }
25
+ it { new_post.must_respond_to :meta }
26
+ it { new_post.must_respond_to :tags }
27
+ it { new_post.must_respond_to :time }
28
+
29
+ describe "#initialize" do
30
+ let(:obj) { post.new(attributes) }
31
+
32
+ it { obj.description.must_equal attributes["description"] }
33
+ it { obj.extended.must_equal attributes["extended"] }
34
+ it { obj.hash.must_equal attributes["hash"] }
35
+ it { obj.href.must_equal attributes["href"] }
36
+ it { obj.tags.must_equal Array(attributes["tags"]) }
37
+ it { obj.time.must_be_kind_of Time }
38
+ end
39
+
40
+ describe "#time" do
41
+ it { post.new("time" => Time.now).time.must_be_kind_of Time }
42
+ it { post.new("time" => Date.new).time.must_be_kind_of Time }
43
+ it { post.new("time" => "2013-01-01").time.must_be_kind_of Time }
44
+ end
45
+
46
+ describe "#tags" do
47
+ it { post.new("tags" => "tag1").tags.must_equal ["tag1"] }
48
+ it { post.new("tags" => "tag1 tag2").tags.must_equal ["tag1", "tag2"] }
49
+ it { post.new("tags" => ["tag1", "tag2"]).tags.must_equal ["tag1", "tag2"] }
50
+ end
51
+
52
+
53
+ describe "self.find" do
54
+ describe "found" do
55
+ before do
56
+ VCR.use_cassette("posts/find/found", preserve_exact_body_bytes: true) do
57
+ @posts = PinboardApi::Post.find("tag" => "test")
58
+ end
59
+ end
60
+
61
+ it { @posts.must_be_kind_of Array }
62
+ it { @posts.wont_be_empty }
63
+ it { @posts.first.href.wont_be_empty }
64
+ end
65
+
66
+ describe "not found" do
67
+ before do
68
+ VCR.use_cassette("posts/find/not_found") do
69
+ @posts = PinboardApi::Post.find("tag" => "xxBOGUSxxINVALIDxx")
70
+ end
71
+ end
72
+
73
+ it { @posts.must_be_empty }
74
+ end
75
+ end
76
+
77
+ describe "self.update" do
78
+ before do
79
+ VCR.use_cassette("posts/update") do
80
+ @last_update = PinboardApi::Post.update
81
+ end
82
+ end
83
+
84
+ it { @last_update.must_be_kind_of Time }
85
+ end
86
+ end
@@ -0,0 +1,14 @@
1
+ require "simplecov"
2
+ SimpleCov.add_filter "spec"
3
+ SimpleCov.command_name "MiniTest"
4
+ SimpleCov.start
5
+
6
+ require "minitest/autorun"
7
+ require "minitest/pride"
8
+ require "mocha"
9
+
10
+ require File.expand_path("../../lib/pinboard_api", __FILE__)
11
+
12
+ # Requires supporting ruby files with custom matchers and macros, etc,
13
+ # in spec/support/ and its subdirectories.
14
+ Dir[File.join("./spec/support/**/*.rb")].sort.each { |f| require f }
@@ -0,0 +1,10 @@
1
+ PinboardApi.username = ENV["PINBOARD_USERNAME"]
2
+ PinboardApi.password = ENV["PINBOARD_PASSWORD"]
3
+
4
+ PinboardApi.ssl_options = ENV["PINBOARD_SSL_OPTIONS"] || begin
5
+ if File.exists?("/opt/local/share/curl/curl-ca-bundle.crt")
6
+ { ca_file: "/opt/local/share/curl/curl-ca-bundle.crt" }
7
+ else
8
+ { ca_path: "/System/Library/OpenSSL" }
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ require "vcr"
2
+ require "base64"
3
+
4
+ VCR.configure do |c|
5
+ c.default_cassette_options = { record: :once, serialize_with: :json }
6
+ c.hook_into :faraday
7
+ c.cassette_library_dir = "spec/fixtures/vcr_cassettes"
8
+ c.filter_sensitive_data("[USERNAME]") { PinboardApi.username }
9
+ c.filter_sensitive_data("[PASSWORD]") { PinboardApi.password }
10
+ c.filter_sensitive_data("[FILTERED]") do
11
+ credentials = [PinboardApi.username, PinboardApi.password].join(":")
12
+ Base64.encode64(credentials).chomp
13
+ end
14
+ end
data/spec/tag_spec.rb ADDED
@@ -0,0 +1,101 @@
1
+ require "spec_helper"
2
+
3
+ describe PinboardApi::Tag do
4
+ it "is defined" do
5
+ defined? PinboardApi::Tag
6
+ end
7
+
8
+ let(:tag) { PinboardApi::Tag.new({"name" => "tag", "count" => 1}) }
9
+
10
+ it { tag.must_respond_to :name }
11
+ it { tag.name.must_equal "tag" }
12
+
13
+ it { tag.must_respond_to :count }
14
+ it { tag.count.must_equal 1 }
15
+
16
+
17
+ describe "self.all" do
18
+ before do
19
+ VCR.use_cassette("tags/all") do
20
+ @tags = PinboardApi::Tag.all
21
+ end
22
+ end
23
+
24
+ it { @tags.wont_be :empty? }
25
+ it { @tags.first.must_be_kind_of PinboardApi::Tag }
26
+ it { @tags.first.name.wont_be :empty? }
27
+ it { @tags.first.count.must_be :>=, 1 }
28
+ end
29
+
30
+
31
+ describe "self.find" do
32
+ describe "found" do
33
+ before do
34
+ VCR.use_cassette("tags/find/found") do
35
+ @tags = PinboardApi::Tag.all
36
+ @tag = PinboardApi::Tag.find(@tags.first.name)
37
+ end
38
+ end
39
+
40
+ it { @tag.must_be_kind_of PinboardApi::Tag }
41
+ it { @tag.name.must_equal @tags.first.name }
42
+ end
43
+
44
+ describe "not found" do
45
+ before do
46
+ VCR.use_cassette("tags/find/not_found") do
47
+ @tag = PinboardApi::Tag.find("xxBOGUSxxINVALIDxx")
48
+ end
49
+ end
50
+
51
+ it { @tag.must_be_nil }
52
+ end
53
+ end
54
+
55
+
56
+ describe "#rename" do
57
+ describe "when successful" do
58
+ before do
59
+ VCR.use_cassette("tags/rename/successful") do
60
+ tag = PinboardApi::Tag.all.first
61
+ @new_name = "z_#{tag.name}"
62
+ @new_tag = tag.rename(@new_name)
63
+ end
64
+ end
65
+
66
+ it { @new_tag.name.must_equal @new_name }
67
+ end
68
+
69
+ describe "when rename fails" do
70
+ it "raises an exception" do
71
+ VCR.use_cassette("tags/rename/unsuccessful") do
72
+ @tag = PinboardApi::Tag.all.first
73
+ -> { @tag.rename("") }.must_raise(RuntimeError)
74
+ end
75
+ end
76
+ end
77
+ end
78
+
79
+
80
+ describe "#delete" do
81
+ describe "when successful" do
82
+ it "returns self when the remote tag has been deleted" do
83
+ VCR.use_cassette("tags/delete/successful") do
84
+ tag = PinboardApi::Tag.find("junk")
85
+ tag.delete.must_equal tag
86
+ end
87
+ end
88
+
89
+ end
90
+
91
+ describe "when delete fails" do
92
+ it "raises an exception" do
93
+ Faraday::Response.any_instance.stubs(:body).returns("")
94
+ VCR.use_cassette("tags/delete/unsuccessful") do
95
+ tag = PinboardApi::Tag.new("name" => "xxINVALIDxxBOGUSxx", "count" => 1)
96
+ -> { tag.delete }.must_raise(RuntimeError)
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
data/spec/user_spec.rb ADDED
@@ -0,0 +1,19 @@
1
+ require "spec_helper"
2
+
3
+ describe PinboardApi::User do
4
+ it "is defined" do
5
+ defined? PinboardApi::User
6
+ end
7
+
8
+ describe "self.secret" do
9
+ before do
10
+ VCR.use_cassette("user/secret") do
11
+ @secret = PinboardApi::User.secret
12
+ end
13
+ end
14
+
15
+ it { @secret.wont_be :empty? }
16
+ it { @secret.size.must_equal 20 }
17
+ it { @secret.must_match /\w{20}/ }
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,273 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pinboard_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Phil Cohen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: faraday
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.8.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.8.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: faraday_middleware
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.8.7
38
+ type: :runtime
39
+ 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
46
+ - !ruby/object:Gem::Dependency
47
+ name: multi_xml
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.5.1
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.5.1
62
+ - !ruby/object:Gem::Dependency
63
+ name: guard-minitest
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: growl
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: minitest
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: mocha
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: rake
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ - !ruby/object:Gem::Dependency
143
+ name: rb-fsevent
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ - !ruby/object:Gem::Dependency
159
+ name: simplecov
160
+ requirement: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ - !ruby/object:Gem::Dependency
175
+ name: vcr
176
+ requirement: !ruby/object:Gem::Requirement
177
+ none: false
178
+ requirements:
179
+ - - ! '>='
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ type: :development
183
+ prerelease: false
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ! '>='
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ description: A Ruby client for the Pinboard.in API
191
+ email:
192
+ - github@phlippers.net
193
+ executables: []
194
+ extensions: []
195
+ extra_rdoc_files: []
196
+ files:
197
+ - .gitignore
198
+ - .ruby-version
199
+ - Gemfile
200
+ - Guardfile
201
+ - LICENSE
202
+ - README.md
203
+ - Rakefile
204
+ - lib/pinboard_api.rb
205
+ - lib/pinboard_api/post.rb
206
+ - lib/pinboard_api/tag.rb
207
+ - lib/pinboard_api/user.rb
208
+ - lib/pinboard_api/version.rb
209
+ - pinboard_api.gemspec
210
+ - spec/fixtures/vcr_cassettes/posts/find/found.json
211
+ - spec/fixtures/vcr_cassettes/posts/find/not_found.json
212
+ - spec/fixtures/vcr_cassettes/posts/update.json
213
+ - spec/fixtures/vcr_cassettes/tags/all.json
214
+ - spec/fixtures/vcr_cassettes/tags/delete/successful.json
215
+ - spec/fixtures/vcr_cassettes/tags/delete/unsuccessful.json
216
+ - spec/fixtures/vcr_cassettes/tags/find/found.json
217
+ - spec/fixtures/vcr_cassettes/tags/find/not_found.json
218
+ - spec/fixtures/vcr_cassettes/tags/rename/successful.json
219
+ - spec/fixtures/vcr_cassettes/tags/rename/unsuccessful.json
220
+ - spec/fixtures/vcr_cassettes/user/secret.json
221
+ - spec/pinboard_api_spec.rb
222
+ - spec/post_spec.rb
223
+ - spec/spec_helper.rb
224
+ - spec/support/pinboard_configuration.rb
225
+ - spec/support/vcr.rb
226
+ - spec/tag_spec.rb
227
+ - spec/user_spec.rb
228
+ homepage: http://phlippers.net/pinboard_api
229
+ licenses: []
230
+ post_install_message:
231
+ rdoc_options: []
232
+ require_paths:
233
+ - lib
234
+ required_ruby_version: !ruby/object:Gem::Requirement
235
+ none: false
236
+ requirements:
237
+ - - ! '>='
238
+ - !ruby/object:Gem::Version
239
+ version: 1.9.2
240
+ required_rubygems_version: !ruby/object:Gem::Requirement
241
+ none: false
242
+ requirements:
243
+ - - ! '>='
244
+ - !ruby/object:Gem::Version
245
+ version: '0'
246
+ segments:
247
+ - 0
248
+ hash: -3411937390163746200
249
+ requirements: []
250
+ rubyforge_project:
251
+ rubygems_version: 1.8.24
252
+ signing_key:
253
+ specification_version: 3
254
+ summary: A Ruby client for the Pinboard.in API
255
+ test_files:
256
+ - spec/fixtures/vcr_cassettes/posts/find/found.json
257
+ - spec/fixtures/vcr_cassettes/posts/find/not_found.json
258
+ - spec/fixtures/vcr_cassettes/posts/update.json
259
+ - spec/fixtures/vcr_cassettes/tags/all.json
260
+ - spec/fixtures/vcr_cassettes/tags/delete/successful.json
261
+ - spec/fixtures/vcr_cassettes/tags/delete/unsuccessful.json
262
+ - spec/fixtures/vcr_cassettes/tags/find/found.json
263
+ - spec/fixtures/vcr_cassettes/tags/find/not_found.json
264
+ - spec/fixtures/vcr_cassettes/tags/rename/successful.json
265
+ - spec/fixtures/vcr_cassettes/tags/rename/unsuccessful.json
266
+ - spec/fixtures/vcr_cassettes/user/secret.json
267
+ - spec/pinboard_api_spec.rb
268
+ - spec/post_spec.rb
269
+ - spec/spec_helper.rb
270
+ - spec/support/pinboard_configuration.rb
271
+ - spec/support/vcr.rb
272
+ - spec/tag_spec.rb
273
+ - spec/user_spec.rb