pinboard 0.0.0 → 0.0.2

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/.autotest ADDED
@@ -0,0 +1 @@
1
+ require 'autotest/bundler'
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ *.gem
2
+ .DS_Store
3
+ .bundle
4
+ .rvmrc
5
+ .yardoc
6
+ Gemfile.lock
7
+ coverage/*
8
+ doc/*
9
+ log/*
10
+ vendor/*
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format=nested
3
+ --backtrace
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - jruby
5
+ - ree
6
+ - ruby-head
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'http://rubygems.org'
2
+
3
+ platforms :jruby do
4
+ gem 'jruby-openssl', '~> 0.7'
5
+ end
6
+
7
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,7 @@
1
+ guard 'rspec', :version => 2 do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
+ watch('spec/helper.rb') { "spec" }
5
+
6
+ end
7
+
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Ryan Walker
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,74 @@
1
+ The Pinboard Ruby Gem
2
+ =====================
3
+ A Ruby wrapper for the [Pinboard API](http://pinboard.in/api/).
4
+
5
+ Installation
6
+ ------------
7
+ gem install pinboard
8
+
9
+ Examples
10
+ --------
11
+
12
+ I'm currently exploring two API interfaces:
13
+
14
+ pinboard = Pinboard::Client.new(:username => 'foo', :password => 'bar')
15
+ posts = pinboard.posts
16
+
17
+ or:
18
+
19
+ posts = Pinboard::Post.all(:username => 'foo', :password => 'bar')
20
+
21
+ Both examples work.
22
+
23
+ Future Examples (I don't need them, so I haven't written them)
24
+ --------------------------------------------------------------
25
+
26
+ pinboard.posts(:tag => 'ruby') #all posts tagged 'ruby'
27
+ pinboard.posts(:start => 20) #starting on the 20th post
28
+ pinboard.posts(:results => 20) #return only first 20 matching posts
29
+ pinboard.posts(:from => 4.days.ago) #all posts in past 4 days
30
+ pinboard.posts(:to => 4.days.ago) #all posts up to 4 days ago
31
+ pinboard.posts(:meta => true) #include meta data in post models
32
+
33
+ Ruby Support & Continuous Integration
34
+ -------------------------------------
35
+ I am using [travis-ci.org](http://travis-ci.org) for continuous
36
+ integration and support of the following rubies in rvm:
37
+
38
+ * 1.8.7
39
+ * 1.9.2
40
+ * jruby
41
+ * ree
42
+ * ruby-head
43
+
44
+ [![Build Status](https://secure.travis-ci.org/ryw/pinboard.png)](http://travis-ci.org/ryw/pinboard)
45
+
46
+ Links
47
+ -----
48
+ * [Pinboard API Documentation](http://pinboard.in/api/)
49
+
50
+ How to Contribute
51
+ -----------------
52
+ If you find what looks like a bug:
53
+
54
+ * Check the [GitHub issue tracker](http://github.com/ryw/pinboard/issues/)
55
+ to see if anyone else has had the same issue.
56
+ * If you don’t see anything, create an issue with information on how to reproduce it.
57
+
58
+ If you want to contribute an enhancement or a fix:
59
+
60
+ * Fork the [project on github](http://github.com/ryw/pinboard).
61
+ * Make your changes with specs.
62
+ * Commit the changes without messing with the Rakefile, VERSION, or history.
63
+ * Send me a pull request.
64
+
65
+ TODO
66
+ ----
67
+
68
+ * Throttle requests to one per second:
69
+ http://datagraph.rubyforge.org/rack-throttle/
70
+ * If get 503 response, double the throttle to two seconds
71
+
72
+ Copyright
73
+ ---------
74
+ Copyright (c) 2011 Ryan Walker. See MIT-LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env rake
2
+
3
+ require 'bundler'
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ require 'rspec/core/rake_task'
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ task :test => :spec
10
+ task :default => :spec
11
+
12
+ namespace :doc do
13
+ require 'yard'
14
+ YARD::Rake::YardocTask.new do |task|
15
+ task.files = ['HISTORY.md', 'LICENSE.md', 'lib/**/*.rb']
16
+ task.options = [
17
+ '--protected',
18
+ '--output-dir', 'doc/yard',
19
+ '--tag', 'format:Supported formats',
20
+ '--tag', 'authenticated:Requires Authentication',
21
+ '--tag', 'rate_limited:Rate Limited',
22
+ '--markup', 'markdown',
23
+ ]
24
+ end
25
+ end
data/lib/pinboard.rb CHANGED
@@ -1,7 +1,15 @@
1
- class Pinboard
1
+ require 'pinboard/util'
2
+ require 'pinboard/client'
3
+ require 'pinboard/post'
2
4
 
3
- def self.hello
4
- puts 'hi'
5
- end
5
+ module Pinboard
6
+ class << self
7
+ def new(options={})
8
+ Pinboard::Client.new(options)
9
+ end
6
10
 
11
+ def endpoint
12
+ Pinboard::Client.base_uri
13
+ end
14
+ end
7
15
  end
@@ -0,0 +1,19 @@
1
+ require 'httparty'
2
+
3
+ module Pinboard
4
+ class Client
5
+ include HTTParty
6
+ base_uri 'api.pinboard.in:443/v1'
7
+
8
+ def initialize(options={})
9
+ @auth = { :username => options[:username],
10
+ :password => options[:password] }
11
+ end
12
+
13
+ def posts
14
+ options = { :basic_auth => @auth }
15
+ posts = self.class.get('/posts/all', options)['posts']['post']
16
+ posts.map { |p| Post.new(Util.symbolize_keys(p)) }
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Pinboard
2
+ class Post < Struct.new(:href, :description, :tag, :time)
3
+ def self.all(options={})
4
+ client = Pinboard::Client.new(options)
5
+ posts = client.class.get('/posts/all',
6
+ :basic_auth => options)['posts']['post']
7
+ posts.map { |p| Post.new(Util.symbolize_keys(p)) }
8
+ end
9
+
10
+ def initialize(attributes={})
11
+ self.time = Util.parse_time(attributes.delete(:time))
12
+ self.tag = attributes.delete(:tag).split(" ")
13
+
14
+ attributes.each do |attribute, value|
15
+ send("#{attribute}=", value) if respond_to?("#{attribute}=")
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Pinboard
2
+ module Util
3
+ extend self
4
+
5
+ def symbolize_keys(hash)
6
+ hash.inject({}) do |options, (key, value)|
7
+ options[(key.to_sym rescue key) || key] = value
8
+ options
9
+ end
10
+ end
11
+
12
+ def parse_time(time)
13
+ return time if time.is_a?(Time)
14
+ return time.to_time if time.is_a?(Date)
15
+
16
+ Time.parse(time)
17
+ end
18
+ end
19
+ end
data/pinboard.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ Gem::Specification.new do |s|
2
+ s.add_development_dependency 'yard', '~> 0.7'
3
+ s.add_development_dependency 'rake', '~> 0.9'
4
+ s.add_development_dependency 'rspec', '~> 2.6'
5
+ s.add_development_dependency 'webmock', '~> 1.6'
6
+ s.add_development_dependency 'guard-rspec', '~> 0.5'
7
+ if RUBY_PLATFORM =~ /darwin/
8
+ s.add_development_dependency "growl_notify"
9
+ s.add_development_dependency "rb-fsevent"
10
+ end
11
+
12
+ s.add_runtime_dependency 'httparty', '~> 0.7'
13
+ s.name = 'pinboard'
14
+ s.version = '0.0.2'
15
+ s.date = '2011-10-13'
16
+ s.summary = "Ruby wrapper for the Pinboard API"
17
+ s.description = "Ruby wrapper for the Pinboard API"
18
+ s.authors = ["Ryan Waker"]
19
+ s.email = 'ry@anotherventure.com'
20
+ s.require_paths = ['lib']
21
+ s.files = `git ls-files`.split("\n")
22
+ s.test_files = `git ls-files -- spec/*`.split("\n")
23
+ s.homepage = 'http://github.com/ryw/pinboard'
24
+ s.required_rubygems_version = Gem::Requirement.new('>= 1.3.6')
25
+ end
@@ -0,0 +1,22 @@
1
+ <?xml version="1.0" encoding="UTF-8" ?>
2
+ <posts user="user">
3
+ <post href="http://foo.com/"
4
+ time="2011-07-26T17:52:04Z"
5
+ description="Foo!"
6
+ extended=""
7
+ tag="foo bar"
8
+ hash="0c85c54332a588d18a85e963257e8fbc"
9
+ meta="5cea9129d6a4f10e4790cc8665c48423"
10
+ toread="yes"
11
+ />
12
+ <post href="http://bar.com/"
13
+ time="2011-07-26T17:52:04Z"
14
+ description="Bar!"
15
+ extended=""
16
+ tag="foo bar"
17
+ hash="0c85c54332a588d18a85e963257e8fbc"
18
+ meta="5cea9129d6a4f10e4790cc8665c48423"
19
+ toread="yes"
20
+ />
21
+ </posts>
22
+
data/spec/helper.rb ADDED
@@ -0,0 +1,25 @@
1
+ require 'pinboard'
2
+ require 'rspec'
3
+ require 'webmock/rspec'
4
+
5
+ def auth_params
6
+ { :username => 'user',
7
+ :password => 'pass' }
8
+ end
9
+
10
+ def a_get(path)
11
+ a_request(:get, Pinboard.endpoint + path)
12
+ end
13
+
14
+ def stub_get(path)
15
+ uri = "https://#{auth_params[:username]}:#{auth_params[:password]}@api.pinboard.in/v1/#{path}"
16
+ stub_request(:get, uri)
17
+ end
18
+
19
+ def fixture_path
20
+ File.expand_path("../fixtures", __FILE__)
21
+ end
22
+
23
+ def fixture(file)
24
+ File.new(fixture_path + '/' + file)
25
+ end
@@ -0,0 +1,30 @@
1
+ require 'helper'
2
+
3
+ describe Pinboard::Client do
4
+ describe "#posts" do
5
+ let(:client) { Pinboard::Client.new(auth_params) }
6
+
7
+ before do
8
+ stub_get("posts/all").
9
+ to_return(:body => fixture("posts_all.xml"),
10
+ :headers => { 'content-type' => 'text/xml' })
11
+ end
12
+
13
+ it "returns a collection of posts" do
14
+ expected = [
15
+ Pinboard::Post.new(
16
+ :href => "http://foo.com/",
17
+ :description => "Foo!",
18
+ :tag => 'foo bar',
19
+ :time => Time.parse("2011-07-26T17:52:04Z")),
20
+ Pinboard::Post.new(
21
+ :href => "http://bar.com/",
22
+ :description => "Bar!",
23
+ :tag => 'foo bar',
24
+ :time => Time.parse("2011-07-26T17:52:04Z"))
25
+ ]
26
+
27
+ client.posts.should == expected
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,43 @@
1
+ require 'helper'
2
+
3
+ describe Pinboard::Post do
4
+
5
+ describe ".all" do
6
+ let(:posts) { Pinboard::Post.all(auth_params) }
7
+
8
+ before do
9
+ stub_get("posts/all").
10
+ to_return(:body => fixture("posts_all.xml"),
11
+ :headers => { 'content-type' => 'text/xml' })
12
+ end
13
+
14
+ it "returns a collection" do
15
+ posts.count.should == 2
16
+ end
17
+
18
+ it "loads posts with valid attributes" do
19
+ post = posts.first
20
+ post.href.should == "http://foo.com/"
21
+ post.description.should == "Foo!"
22
+ post.tag.should == ["foo", "bar"]
23
+ post.time.should == Time.parse('Tue Jul 26 17:52:04 UTC 2011')
24
+ end
25
+ end
26
+
27
+ describe ".new" do
28
+ let(:post) {
29
+ Pinboard::Post.new(
30
+ :href => 'http://foo.com',
31
+ :description => 'Foo!',
32
+ :tag => 'rspec pinboard',
33
+ :time => Time.mktime(2011, 1, 1))
34
+ }
35
+
36
+ it "initializes attributes" do
37
+ post.href.should == 'http://foo.com'
38
+ post.description.should == 'Foo!'
39
+ post.tag.should == %w{rspec pinboard}
40
+ post.time.should == Time.mktime(2011, 1, 1)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,21 @@
1
+ require 'helper'
2
+
3
+ describe Pinboard do
4
+
5
+ describe ".new" do
6
+
7
+ it "returns a Pinboard client" do
8
+ Pinboard.new.should be_a Pinboard::Client
9
+ end
10
+
11
+ end
12
+
13
+ describe ".endpoint" do
14
+
15
+ it "sets the endpoint" do
16
+ Pinboard.endpoint.should == 'https://api.pinboard.in:443/v1'
17
+ end
18
+
19
+ end
20
+
21
+ end
metadata CHANGED
@@ -1,26 +1,142 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pinboard
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 0
10
- version: 0.0.0
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
- - Ry Waker
13
+ - Ryan Waker
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-28 00:00:00 -04:00
19
- default_executable:
20
- dependencies: []
21
-
18
+ date: 2011-10-13 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: yard
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 5
29
+ segments:
30
+ - 0
31
+ - 7
32
+ version: "0.7"
33
+ type: :development
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rake
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ hash: 25
44
+ segments:
45
+ - 0
46
+ - 9
47
+ version: "0.9"
48
+ type: :development
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: rspec
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ hash: 15
59
+ segments:
60
+ - 2
61
+ - 6
62
+ version: "2.6"
63
+ type: :development
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: webmock
67
+ prerelease: false
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ~>
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 1
76
+ - 6
77
+ version: "1.6"
78
+ type: :development
79
+ version_requirements: *id004
80
+ - !ruby/object:Gem::Dependency
81
+ name: guard-rspec
82
+ prerelease: false
83
+ requirement: &id005 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ~>
87
+ - !ruby/object:Gem::Version
88
+ hash: 1
89
+ segments:
90
+ - 0
91
+ - 5
92
+ version: "0.5"
93
+ type: :development
94
+ version_requirements: *id005
95
+ - !ruby/object:Gem::Dependency
96
+ name: growl_notify
97
+ prerelease: false
98
+ requirement: &id006 !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ hash: 3
104
+ segments:
105
+ - 0
106
+ version: "0"
107
+ type: :development
108
+ version_requirements: *id006
109
+ - !ruby/object:Gem::Dependency
110
+ name: rb-fsevent
111
+ prerelease: false
112
+ requirement: &id007 !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ hash: 3
118
+ segments:
119
+ - 0
120
+ version: "0"
121
+ type: :development
122
+ version_requirements: *id007
123
+ - !ruby/object:Gem::Dependency
124
+ name: httparty
125
+ prerelease: false
126
+ requirement: &id008 !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ~>
130
+ - !ruby/object:Gem::Version
131
+ hash: 5
132
+ segments:
133
+ - 0
134
+ - 7
135
+ version: "0.7"
136
+ type: :runtime
137
+ version_requirements: *id008
22
138
  description: Ruby wrapper for the Pinboard API
23
- email: ry@rywalker.com
139
+ email: ry@anotherventure.com
24
140
  executables: []
25
141
 
26
142
  extensions: []
@@ -28,9 +144,26 @@ extensions: []
28
144
  extra_rdoc_files: []
29
145
 
30
146
  files:
147
+ - .autotest
148
+ - .gitignore
149
+ - .rspec
150
+ - .travis.yml
151
+ - Gemfile
152
+ - Guardfile
153
+ - MIT-LICENSE
154
+ - README.md
155
+ - Rakefile
31
156
  - lib/pinboard.rb
32
- has_rdoc: true
33
- homepage: http://rubygems.org/gems/pinboard
157
+ - lib/pinboard/client.rb
158
+ - lib/pinboard/post.rb
159
+ - lib/pinboard/util.rb
160
+ - pinboard.gemspec
161
+ - spec/fixtures/posts_all.xml
162
+ - spec/helper.rb
163
+ - spec/pinboard/client_spec.rb
164
+ - spec/pinboard/post_spec.rb
165
+ - spec/pinboard_spec.rb
166
+ homepage: http://github.com/ryw/pinboard
34
167
  licenses: []
35
168
 
36
169
  post_install_message:
@@ -52,16 +185,22 @@ required_rubygems_version: !ruby/object:Gem::Requirement
52
185
  requirements:
53
186
  - - ">="
54
187
  - !ruby/object:Gem::Version
55
- hash: 3
188
+ hash: 23
56
189
  segments:
57
- - 0
58
- version: "0"
190
+ - 1
191
+ - 3
192
+ - 6
193
+ version: 1.3.6
59
194
  requirements: []
60
195
 
61
196
  rubyforge_project:
62
- rubygems_version: 1.6.2
197
+ rubygems_version: 1.8.9
63
198
  signing_key:
64
199
  specification_version: 3
65
200
  summary: Ruby wrapper for the Pinboard API
66
- test_files: []
67
-
201
+ test_files:
202
+ - spec/fixtures/posts_all.xml
203
+ - spec/helper.rb
204
+ - spec/pinboard/client_spec.rb
205
+ - spec/pinboard/post_spec.rb
206
+ - spec/pinboard_spec.rb