hatena-bookmark-restful 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a8263ea79da036e3c5185b5fad03fb57469052a7
4
+ data.tar.gz: 618a5bb0b065737ef075f884298be82637d33c52
5
+ SHA512:
6
+ metadata.gz: ff07f9681bbf047ee5cc678e19a6c8a51dff76d486ee62149a9a4f98b978a4d1922772cbcee97a189772fcf7b462f8293517e8f2ba1893a0a508426d702b235b
7
+ data.tar.gz: a9c7056464cbb3bcb825361f6602517bd67e33aea6627333ddf32f3e909f029eb02748fd7fc5a2cda738e89903a315e57b64df4f78ae038ec95c9e83d7497d3a
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,21 @@
1
+ ---
2
+ language: ruby
3
+ rvm:
4
+ - 2.1.0
5
+ - 2.0.0
6
+ - 1.9.3
7
+ - jruby-19mode
8
+ - ruby-head
9
+ - jruby-head
10
+ bundler_args: -j4
11
+ before_install:
12
+ - gem update --system
13
+ - gem --version
14
+ - gem install bundler --pre
15
+ script: bundle exec rake spec
16
+ matrix:
17
+ allow_failures:
18
+ -
19
+ rvm:
20
+ - ruby-head
21
+ - jruby-head
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hatena-bookmark-restful.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 aereal
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,49 @@
1
+ * `master` status: ![master Build Status](https://travis-ci.org/aereal/hatena-bookmark-restful.png?branch=master)
2
+ * `develop` status: ![develop Build Status](https://travis-ci.org/aereal/hatena-bookmark-restful.png?branch=develop)
3
+
4
+ # Hatena::Bookmark::Restful
5
+
6
+ A client library for [Hatena::Bookmark RESTful API](http://developer.hatena.ne.jp/ja/documents/bookmark/apis/rest).
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'hatena-bookmark-restful'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install hatena-bookmark-restful
21
+
22
+ ## Usage
23
+
24
+ **NOTICE**: You must read and agree to [terms of services (in Japanese)](http://developer.hatena.ne.jp/ja/license) before using the API.
25
+
26
+ ```
27
+ require 'hatena/bookmark/restful/v1'
28
+ CONSUMER_KEY = 'YOUR_CONSUMER_KEY'
29
+ CONSUMER_SECRET = 'YOUR_CONSUMER_SECRET'
30
+ ACCESS_TOKEN = 'YOUR_ACCESS_TOKEN'
31
+ ACCESS_TOKEN_SECRET = 'YOUR_ACCESS_TOKEN_SECRET'
32
+
33
+ client = Hatena::Bookmark::Restful::V1.new(
34
+ consumer_key: CONSUMER_KEY,
35
+ consumer_secret: CONSUMER_SECRET,
36
+ access_token: ACCESS_TOKEN,
37
+ access_token_secret: ACCESS_TOKEN_SECRET
38
+ )
39
+
40
+ client.bookmark('http://www.hatena.ne.jp/')
41
+ ```
42
+
43
+ ## Contributing
44
+
45
+ 1. Fork it ( http://github.com/aereal/hatena-bookmark-restful/fork )
46
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
47
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
48
+ 4. Push to the branch (`git push origin my-new-feature`)
49
+ 5. Create new Pull Request
@@ -0,0 +1,64 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ require "semantic"
4
+ require "yard"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task :default => :spec
9
+
10
+ def update_version!(file_path)
11
+ old_file = File.read(file_path)
12
+ version_str = old_file[VERSION_PATTERN, 1]
13
+ old_version = Semantic::Version.new(version_str)
14
+ new_version = yield old_version
15
+ modified = old_file.sub(VERSION_PATTERN, new_version.to_s)
16
+ File.open(file_path, 'w') {|f| f.write(modified) }
17
+ warn "#{old_version} => #{new_version}"
18
+ end
19
+
20
+ VERSION_FILE = 'lib/hatena/bookmark/restful/version.rb'
21
+ VERSION_PATTERN = /(\d+\.\d+\.\d+)(-([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?(\+([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?/.freeze # Stolen from Semantic::Version::SemVerRegexp
22
+ namespace :version do
23
+ namespace :major do
24
+ desc "bump major version"
25
+ task :bump => VERSION_FILE do |t|
26
+ update_version!(t.prerequisites.first) do |new_version|
27
+ new_version.tap do |version|
28
+ version.major += 1
29
+ version.minor = 0
30
+ version.patch = 0
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ namespace :minor do
37
+ desc "bump minor version"
38
+ task :bump => VERSION_FILE do |t|
39
+ update_version!(t.prerequisites.first) do |new_version|
40
+ new_version.tap do |version|
41
+ version.minor += 1
42
+ version.patch = 0
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ namespace :patch do
49
+ desc "bump patch version"
50
+ task :bump => VERSION_FILE do |t|
51
+ update_version!(t.prerequisites.first) do |new_version|
52
+ new_version.tap do |version|
53
+ version.patch += 1
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+ YARD::Rake::YardocTask.new(:doc) do |t|
61
+ spec = Gem::Specification.find_by_name('hatena-bookmark-restful')
62
+ t.files = spec.lib_files
63
+ t.options = %w( --readme README.md )
64
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hatena/bookmark/restful/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "hatena-bookmark-restful"
8
+ spec.version = Hatena::Bookmark::Restful::VERSION
9
+ spec.authors = ["aereal"]
10
+ spec.email = ["aereal@aereal.org"]
11
+ spec.summary = %q{A client library for Hatena::Bookmark RESTful API}
12
+ spec.description = %q{A client library for Hatena::Bookmark RESTful API}
13
+ spec.homepage = "https://github.com/aereal/hatena-bookmark-restful"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "faraday"
22
+ spec.add_runtime_dependency "faraday_middleware"
23
+ spec.add_runtime_dependency "simple_oauth"
24
+ spec.add_development_dependency "bundler", "~> 1.5"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "semantic"
28
+ spec.add_development_dependency "yard"
29
+ end
@@ -0,0 +1 @@
1
+ require "hatena/bookmark/restful"
@@ -0,0 +1,8 @@
1
+ require "hatena/bookmark/restful/version"
2
+
3
+ module Hatena
4
+ module Bookmark
5
+ module Restful
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,110 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+ require 'json'
4
+ require 'hatena/bookmark/restful/v1/user'
5
+ require 'hatena/bookmark/restful/v1/tag'
6
+ require 'hatena/bookmark/restful/v1/entry'
7
+ require 'hatena/bookmark/restful/v1/bookmark'
8
+
9
+ module Hatena
10
+ module Bookmark
11
+ module Restful; end
12
+ end
13
+ end
14
+
15
+ class Hatena::Bookmark::Restful::V1
16
+ BASE_URI = 'http://api.b.hatena.ne.jp'
17
+ API_VERSION = '1'
18
+
19
+ class Credentials
20
+ # @!attribute [rw] consumer_key
21
+ # @return [String]
22
+ # @!attribute [rw] consumer_secret
23
+ # @return [String]
24
+ # @!attribute [rw] access_token
25
+ # @return [String]
26
+ # @!attribute [rw] access_token_secret
27
+ # @return [String]
28
+ attr_accessor :consumer_key, :consumer_secret, :access_token, :access_token_secret
29
+
30
+ # @param [Hash] attributes
31
+ # @option attributes [String] :consumer_key
32
+ # @option attributes [String] :consumer_secret
33
+ # @option attributes [String] :access_token
34
+ # @option attributes [String] :access_token_secret
35
+ def initialize(attributes)
36
+ @consumer_key = attributes.fetch(:consumer_key)
37
+ @consumer_secret = attributes.fetch(:consumer_secret)
38
+ @access_token = attributes.fetch(:access_token)
39
+ @access_token_secret = attributes.fetch(:access_token_secret)
40
+ end
41
+ end
42
+
43
+ def initialize(credentials)
44
+ @credentials = credentials
45
+ end
46
+
47
+ # @return [User]
48
+ def my
49
+ res = connection.get("/#{api_version}/my")
50
+ attrs = JSON.parse(res.body)
51
+ user = User.new_from_response(attrs)
52
+ end
53
+
54
+ # @return [<Tag>]
55
+ def my_tags
56
+ res = connection.get("/#{api_version}/my/tags")
57
+ attrs = JSON.parse(res.body)
58
+ raw_tags = attrs.fetch('tags')
59
+ tags = raw_tags.map {|t| Tag.new_from_response(t) }
60
+ end
61
+
62
+ # @return [Entry]
63
+ def entry(url)
64
+ res = connection.get("/#{api_version}/entry", url: url)
65
+ attrs = JSON.parse(res.body)
66
+ entry = Entry.new_from_response(attrs)
67
+ end
68
+
69
+ # @return [Bookmark]
70
+ def bookmark(url)
71
+ res = connection.get("/#{api_version}/my/bookmark", url: url)
72
+ attrs = JSON.parse(res.body)
73
+ bookmark = Bookmark.new_from_response(attrs)
74
+ end
75
+
76
+ # @return [Boolean]
77
+ def delete_bookmark(url)
78
+ res = connection.delete("/#{api_version}/my/bookmark", url: url)
79
+ res.success?
80
+ end
81
+
82
+ # @return [Bookmark]
83
+ def create_bookmark(bookmark_params)
84
+ res = connection.post("/#{api_version}/my/bookmark", bookmark_params)
85
+ attrs = JSON.parse(res.body)
86
+ bookmark = Bookmark.new_from_response(attrs)
87
+ end
88
+
89
+ def api_version
90
+ API_VERSION
91
+ end
92
+
93
+ def base_uri
94
+ BASE_URI
95
+ end
96
+
97
+ private
98
+
99
+ def connection
100
+ @connection ||= Faraday.new(url: base_uri) do |faraday|
101
+ faraday.request :url_encoded
102
+ faraday.request :oauth,
103
+ consumer_key: @credentials.consumer_key,
104
+ consumer_secret: @credentials.consumer_secret,
105
+ token: @credentials.access_token,
106
+ token_secret: @credentials.access_token_secret
107
+ faraday.adapter Faraday.default_adapter
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,30 @@
1
+ require "hatena/bookmark/restful/v1/response_object"
2
+
3
+ module Hatena
4
+ module Bookmark
5
+ module Restful
6
+ class V1
7
+ class Bookmark
8
+ # @!attribute [r] comment
9
+ # @return [String]
10
+ # @!attribute [r] created_datetime
11
+ # @return [String]
12
+ # @!attribute [r] created_epoch
13
+ # @return [Integer]
14
+ # @!attribute [r] user
15
+ # @return [String]
16
+ # @!attribute [r] permalink
17
+ # @return [String]
18
+ # @!attribute [r] private
19
+ # @return [Boolean]
20
+ # @!attribute [r] tags
21
+ # @note Return value is a array of **String representation of the tag**
22
+ # @return [<String>]
23
+ PROPERTIES = [:comment, :created_datetime, :created_epoch, :user, :permalink, :private, :tags]
24
+
25
+ include Hatena::Bookmark::Restful::V1::ResponseObject
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,27 @@
1
+ require "hatena/bookmark/restful/v1/response_object"
2
+
3
+ module Hatena
4
+ module Bookmark
5
+ module Restful
6
+ class V1; end
7
+ end
8
+ end
9
+ end
10
+
11
+ class Hatena::Bookmark::Restful::V1::Entry
12
+ # @!attribute [r] title
13
+ # @return [String]
14
+ # @!attribute [r] url
15
+ # @return [String]
16
+ # @!attribute [r] entry_url
17
+ # @return [String]
18
+ # @!attribute [r] count
19
+ # @return [Integer]
20
+ # @!attribute [r] favicon_url
21
+ # @return [String]
22
+ # @!attribute [r] smartphone_app_entry_url
23
+ # @return [String]
24
+ PROPERTIES = [:title, :url, :entry_url, :count, :favicon_url, :smartphone_app_entry_url]
25
+
26
+ include Hatena::Bookmark::Restful::V1::ResponseObject
27
+ end
@@ -0,0 +1,48 @@
1
+ module Hatena
2
+ module Bookmark
3
+ module Restful
4
+ class V1; end
5
+ end
6
+ end
7
+ end
8
+
9
+ module Hatena::Bookmark::Restful::V1::ResponseObject
10
+ module ClassMethods
11
+ # Create a new instance from JSON from the API
12
+ def new_from_response(res)
13
+ properties = self.const_get(:PROPERTIES)
14
+ names = properties.map(&:to_s)
15
+ values = res.values_at(*names)
16
+ attrs = Hash[ properties.zip(values) ]
17
+ new(attrs)
18
+ end
19
+ end
20
+
21
+ def self.included(context)
22
+ properties = context.const_get(:PROPERTIES)
23
+ context.send(:extend, ClassMethods)
24
+ properties.each do |prop|
25
+ define_method(prop) { @attributes.fetch(prop) }
26
+ end
27
+ end
28
+
29
+ def initialize(attributes)
30
+ @attributes = attributes
31
+ end
32
+
33
+ # Fetch raw attribute value
34
+ # @param [Symbol] name The attribute's name
35
+ def [](name)
36
+ @attributes[name]
37
+ end
38
+
39
+ # @return [Boolean]
40
+ def ==(other)
41
+ other.is_a?(self.class) && self.class.const_get(:PROPERTIES).all? {|prop| self[prop] == other[prop] }
42
+ end
43
+
44
+ # @return [Hash]
45
+ def to_hash
46
+ @attributes
47
+ end
48
+ end
@@ -0,0 +1,33 @@
1
+ require "hatena/bookmark/restful/v1/response_object"
2
+
3
+ module Hatena
4
+ module Bookmark
5
+ module Restful
6
+ class V1; end
7
+ end
8
+ end
9
+ end
10
+
11
+ class Hatena::Bookmark::Restful::V1::Tag
12
+ # @!attribute [r] tag
13
+ # The name of tag
14
+ # @return [String]
15
+ # @!attribute [r] count
16
+ # The number of bookmarks with the tag
17
+ # @return [Integer]
18
+ # @!attribute [r] modified_datetime
19
+ # ISO 8601 representation of the last modified time
20
+ # @return [String]
21
+ # @!attribute [r] modified_epoch
22
+ # UNIX epoch of the last modified time
23
+ # @return [Integer]
24
+ PROPERTIES = [:tag, :count, :modified_epoch, :modified_datetime]
25
+
26
+ include Hatena::Bookmark::Restful::V1::ResponseObject
27
+
28
+ # The last modified time
29
+ # @return [Time]
30
+ def modified_at
31
+ Time.at(self.modified_epoch)
32
+ end
33
+ end
@@ -0,0 +1,44 @@
1
+ require "hatena/bookmark/restful/v1/response_object"
2
+
3
+ module Hatena
4
+ module Bookmark
5
+ module Restful
6
+ class V1; end
7
+ end
8
+ end
9
+ end
10
+
11
+ class Hatena::Bookmark::Restful::V1::User
12
+ # @!attribute [r] name
13
+ # User's Hatena ID
14
+ # @return [String]
15
+ STRING_PROPERTIES = [:name]
16
+ BOOLEAN_PROPERTIES = [:plususer, :private, :is_oauth_twitter, :is_oauth_evernote, :is_oauth_facebook, :is_oauth_mixi_check]
17
+ PROPERTIES = STRING_PROPERTIES + BOOLEAN_PROPERTIES
18
+
19
+ include Hatena::Bookmark::Restful::V1::ResponseObject
20
+
21
+ # @!method plususer?
22
+ # The user subscribed Hatena Bookmark Plus or not
23
+ # @return [Boolean]
24
+ # @!method private?
25
+ # The user does not share his/her bookmarks with anyone or not
26
+ # @return [Boolean]
27
+ # @!method oauth_twitter?
28
+ # Connected with Twitter using OAuth or not
29
+ # @return [Boolean]
30
+ # @!method oauth_evernote?
31
+ # Connected with Evernote using OAuth or not
32
+ # @return [Boolean]
33
+ # @!method oauth_facebook?
34
+ # Connected with Facebook using OAuth or not
35
+ # @return [Boolean]
36
+ # @!method oauth_mixi_check?
37
+ # Connected with mixi check using OAuth or not
38
+ # @return [Boolean]
39
+ BOOLEAN_PROPERTIES.each do |prop|
40
+ define_method(prop.to_s.gsub(/^is_/, '')) do
41
+ @attributes.fetch(prop)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,7 @@
1
+ module Hatena
2
+ module Bookmark
3
+ module Restful
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,219 @@
1
+ # encoding: utf-8
2
+
3
+ require 'hatena/bookmark/restful/v1'
4
+ require 'json'
5
+
6
+ shared_context "send a HTTP request to API" do
7
+ subject { raise "The example group must give real `subject`" }
8
+
9
+ let(:api_path) { raise "The example group must give real `api_path`" }
10
+
11
+ let(:stubbed_response) {
12
+ [
13
+ 200,
14
+ {},
15
+ response_body
16
+ ]
17
+ }
18
+
19
+ let(:test_connection) {
20
+ Faraday.new do |builder|
21
+ builder.adapter :test do |stubs|
22
+ stubs.get(api_path) { stubbed_response }
23
+ end
24
+ end
25
+ }
26
+
27
+ before do
28
+ allow(client).to receive(:connection).and_return(test_connection)
29
+ end
30
+ end
31
+
32
+ describe Hatena::Bookmark::Restful::V1 do
33
+ let(:credentials) { Hatena::Bookmark::Restful::V1::Credentials.new(consumer_key: '', consumer_secret: '', access_token: '', access_token_secret: '') }
34
+ let(:client) { Hatena::Bookmark::Restful::V1.new(credentials) }
35
+
36
+ describe "#create_bookmark" do
37
+ let(:stubbed_response) {
38
+ [
39
+ 200,
40
+ {},
41
+ JSON.dump(bookmark.to_hash)
42
+ ]
43
+ }
44
+
45
+ let(:test_connection) {
46
+ Faraday.new do |builder|
47
+ builder.adapter :test do |stubs|
48
+ stubs.post(api_path) { stubbed_response }
49
+ end
50
+ end
51
+ }
52
+
53
+ let(:api_path) { "/1/my/bookmark" }
54
+
55
+ let(:request_params) {
56
+ {
57
+ url: 'http://www.hatena.ne.jp/',
58
+ comment: 'おもしろホームページです',
59
+ tags: %w( hatena ),
60
+ post_twitter: false,
61
+ post_facebook: false,
62
+ post_mixi: false,
63
+ post_evernote: false,
64
+ send_mail: false,
65
+ private: false,
66
+ }
67
+ }
68
+
69
+ let(:bookmark) {
70
+ Hatena::Bookmark::Restful::V1::Bookmark.new_from_response(
71
+ 'comment' => request_params[:comment],
72
+ 'created_datetime' => '2013-12-17T23:58:54+09:00',
73
+ 'created_epoch' => 1387292334,
74
+ 'user' => 'aereal',
75
+ 'permalink' => 'http://b.hatena.ne.jp/aereal/20131217#bookmark-150288466',
76
+ 'private' => request_params['private'],
77
+ 'tags' => request_params['tags'],
78
+ )
79
+ }
80
+
81
+ before do
82
+ allow(client).to receive(:connection).and_return(test_connection)
83
+ end
84
+
85
+ it "successfully create a new bookmark" do
86
+ expect(client.create_bookmark(request_params)).to eq(bookmark)
87
+ end
88
+ end
89
+
90
+ describe "#delete_bookmark" do
91
+ let(:stubbed_response) {
92
+ [
93
+ 204,
94
+ {},
95
+ ''
96
+ ]
97
+ }
98
+
99
+ let(:test_connection) {
100
+ Faraday.new do |builder|
101
+ builder.adapter :test do |stubs|
102
+ stubs.delete(api_path) { stubbed_response }
103
+ end
104
+ end
105
+ }
106
+
107
+ let(:api_path) { "/1/my/bookmark" }
108
+
109
+ let(:entry_url) { "http://aereal.org/" }
110
+
111
+ before do
112
+ allow(client).to receive(:connection).and_return(test_connection)
113
+ end
114
+
115
+ it "successfully delete a bookmark" do
116
+ expect(client.delete_bookmark(entry_url)).to be_true
117
+ end
118
+ end
119
+
120
+ describe "#bookmark" do
121
+ include_context "send a HTTP request to API"
122
+
123
+ subject { client.bookmark(entry_url) }
124
+
125
+ let(:api_path) { "/1/my/bookmark" }
126
+
127
+ let(:bookmark) {
128
+ Hatena::Bookmark::Restful::V1::Bookmark.new_from_response(
129
+ 'comment' => ' Heroku の Deploy Hooks で HipChat がサポートされていた',
130
+ 'created_datetime' => '2013-12-17T23:58:54+09:00',
131
+ 'created_epoch' => 1387292334,
132
+ 'user' => 'aereal',
133
+ 'permalink' => 'http://b.hatena.ne.jp/aereal/20131217#bookmark-150288466',
134
+ 'private' => false,
135
+ 'tags' => [
136
+ 'heroku',
137
+ ],
138
+ )
139
+ }
140
+
141
+ let(:response_body) { JSON.dump(bookmark.to_hash) }
142
+
143
+ let(:entry_url) { "https://devcenter.heroku.com/articles/deploy-hooks" }
144
+
145
+ it "is valid response from API" do
146
+ expect(client.bookmark(entry_url)).to eq(bookmark)
147
+ end
148
+ end
149
+
150
+ describe "#entry" do
151
+ include_context "send a HTTP request to API"
152
+ let(:api_path) { "/1/entry" }
153
+
154
+ let(:entry) {
155
+ Hatena::Bookmark::Restful::V1::Entry.new_from_response(
156
+ 'title' => %|aereal's portfolio - aereal.org|,
157
+ 'url' => 'http://aereal.org/',
158
+ 'entry_url' => 'http://b.hatena.ne.jp/entry/aereal.org/',
159
+ 'count' => 3,
160
+ 'favicon_url' => 'http://cdn-ak.favicon.st-hatena.com/?url=http%3A%2F%2Faereal.org%2F',
161
+ 'smartphone_app_entry_url' => 'http://b.hatena.ne.jp/bookmarklet.touch?mode=comment&iphone_app=1&url=http%3A%2F%2Faereal.org%2F',
162
+ )
163
+ }
164
+
165
+ let(:response_body) { JSON.generate(entry.to_hash) }
166
+
167
+ let(:entry_url) { 'http://aereal.org/' }
168
+
169
+ it "is valid response from API" do
170
+ expect(client.entry(entry_url)).to eq(entry)
171
+ end
172
+ end
173
+
174
+ describe "#tags" do
175
+ include_context "send a HTTP request to API"
176
+ let(:api_path) { "/1/my/tags" }
177
+
178
+ let(:tag) {
179
+ Hatena::Bookmark::Restful::V1::Tag.new_from_response(
180
+ 'modified_datetime' => '2011-06-15T05:41:01',
181
+ 'modified_epoch' => 1308116461,
182
+ 'count' => 10,
183
+ 'tag' => 'ruby',
184
+ )
185
+ }
186
+
187
+ let(:tags_response) { { 'tags' => [tag.to_hash] } }
188
+
189
+ let(:response_body) { JSON.generate(tags_response) }
190
+
191
+ it "is valid response from API" do
192
+ expect(client.my_tags).to eq([ tag ])
193
+ end
194
+ end
195
+
196
+ describe "#my" do
197
+ include_context "send a HTTP request to API"
198
+
199
+ let(:user) {
200
+ Hatena::Bookmark::Restful::V1::User.new_from_response(
201
+ 'name' => 'aereal',
202
+ 'plususer' => true,
203
+ 'private' => false,
204
+ 'is_oauth_twitter' => true,
205
+ 'is_oauth_evernote' => true,
206
+ 'is_oauth_facebook' => true,
207
+ 'is_oauth_mixi_check' => false,
208
+ )
209
+ }
210
+
211
+ let(:response_body) { JSON.dump(user.to_hash) }
212
+
213
+ let(:api_path) { "/1/my" }
214
+
215
+ it "is valid response from API" do
216
+ expect(client.my).to eq(user)
217
+ end
218
+ end
219
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hatena::Bookmark::Restful do
4
+ it 'should have a version number' do
5
+ Hatena::Bookmark::Restful::VERSION.should_not be_nil
6
+ end
7
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'hatena/bookmark/restful'
metadata ADDED
@@ -0,0 +1,180 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hatena-bookmark-restful
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - aereal
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: simple_oauth
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.5'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.5'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: semantic
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: yard
113
+ requirement: !ruby/object:Gem::Requirement
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
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: A client library for Hatena::Bookmark RESTful API
126
+ email:
127
+ - aereal@aereal.org
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".rspec"
134
+ - ".travis.yml"
135
+ - Gemfile
136
+ - LICENSE.txt
137
+ - README.md
138
+ - Rakefile
139
+ - hatena-bookmark-restful.gemspec
140
+ - lib/hatena-bookmark-restful.rb
141
+ - lib/hatena/bookmark/restful.rb
142
+ - lib/hatena/bookmark/restful/v1.rb
143
+ - lib/hatena/bookmark/restful/v1/bookmark.rb
144
+ - lib/hatena/bookmark/restful/v1/entry.rb
145
+ - lib/hatena/bookmark/restful/v1/response_object.rb
146
+ - lib/hatena/bookmark/restful/v1/tag.rb
147
+ - lib/hatena/bookmark/restful/v1/user.rb
148
+ - lib/hatena/bookmark/restful/version.rb
149
+ - spec/hatena/bookmark/restful/v1_spec.rb
150
+ - spec/hatena/bookmark/restful_spec.rb
151
+ - spec/spec_helper.rb
152
+ homepage: https://github.com/aereal/hatena-bookmark-restful
153
+ licenses:
154
+ - MIT
155
+ metadata: {}
156
+ post_install_message:
157
+ rdoc_options: []
158
+ require_paths:
159
+ - lib
160
+ required_ruby_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ requirements: []
171
+ rubyforge_project:
172
+ rubygems_version: 2.2.0
173
+ signing_key:
174
+ specification_version: 4
175
+ summary: A client library for Hatena::Bookmark RESTful API
176
+ test_files:
177
+ - spec/hatena/bookmark/restful/v1_spec.rb
178
+ - spec/hatena/bookmark/restful_spec.rb
179
+ - spec/spec_helper.rb
180
+ has_rdoc: