hatena_bookmark_client_for_ruby 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 66f30d10f99bc446ec8ffb61c2069d49f5185a509bbb6924d77ad2b8eaa80661
4
- data.tar.gz: 3eee9f9a56ec42944bb013de470954ab84c83c64dd02b31803e50fd69e3769ec
3
+ metadata.gz: 6c72146c7ca29f776e2686b07007c7016e7ceace21750c97676ae4f97626c001
4
+ data.tar.gz: afd192f1e764223090caca0e03a4f582cfc2203e30abcae8931ce2706e21f663
5
5
  SHA512:
6
- metadata.gz: 7403f5e6c3ce87c79a256392939d31a104fac3fbc8be8b355799d0929452bcd5cb7b8c5e8249994fe43e73ca01769c622a83893e6611284a112c2bc456cb6150
7
- data.tar.gz: 6feb890411b47937f7c0eccc5561122d8bc417d398e0fdfc628cced255c3669443f56aed068f1115e54354a991e5d83227cfd3bbe9e513a3aceedf304428a39e
6
+ metadata.gz: e37900dbcf6df1470db9579952dcdf713ee9f2fbd1b537903268ea7ee72a6c33aa149e49c88d7993cdae34a15c6b3d9d0e4f81d85fc7442b3eb51c92bd954fee
7
+ data.tar.gz: f23e46f1a4fcbbda6d4865ae1d8a22545f1ce424701fcefd21da8a11237e10ff00d5965830db5e53a8c4842c4b85c13df72283ab68a259a3e4da3a69d58202fc
data/.gitignore CHANGED
@@ -6,6 +6,7 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
-
9
+ /vendor/
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+ .rufo
data/Gemfile.lock CHANGED
@@ -2,11 +2,18 @@ PATH
2
2
  remote: .
3
3
  specs:
4
4
  hatena_bookmark_client_for_ruby (0.1.0)
5
+ crack
6
+ json
7
+ oauth
5
8
 
6
9
  GEM
7
10
  remote: https://rubygems.org/
8
11
  specs:
12
+ crack (0.4.3)
13
+ safe_yaml (~> 1.0.0)
9
14
  diff-lcs (1.3)
15
+ json (2.2.0)
16
+ oauth (0.5.4)
10
17
  rake (10.5.0)
11
18
  rspec (3.8.0)
12
19
  rspec-core (~> 3.8.0)
@@ -21,6 +28,7 @@ GEM
21
28
  diff-lcs (>= 1.2.0, < 2.0)
22
29
  rspec-support (~> 3.8.0)
23
30
  rspec-support (3.8.0)
31
+ safe_yaml (1.0.5)
24
32
 
25
33
  PLATFORMS
26
34
  ruby
data/README.md CHANGED
@@ -1,28 +1,31 @@
1
1
  # HatenaBookmarkClientForRuby
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/hatena_bookmark_client_for_ruby`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ `HatenaBookmarkClientForRuby` is simple Ruby networking library for Hatena bookmark Web API
6
4
 
7
5
  ## Installation
8
6
 
9
- Add this line to your application's Gemfile:
10
7
 
11
- ```ruby
12
- gem 'hatena_bookmark_client_for_ruby'
8
+ ```sh
9
+ gem install hatena_ebookmark_client_for_ruby
13
10
  ```
14
11
 
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
12
+ ## Example
20
13
 
21
- $ gem install hatena_bookmark_client_for_ruby
22
-
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
14
+ ```ruby
15
+ require 'hatena_bookmark_client_for_ruby'
16
+ hatebu = HatenaBookmarkClientForRuby::Bookmark.new(
17
+ consumer_key: CONSUMER_KEY,
18
+ consumer_secret: CONSUMER_SECRET,
19
+ request_token: REQUEST_TOKEN,
20
+ request_secret: REQUEST_SECRET,
21
+ )
22
+ body = {
23
+ url: "http://developer.hatena.ne.jp/ja/documents/bookmark/apis/rest/bookmark#post_my_bookmark",
24
+ comment: "test",
25
+ }
26
+ response = hatebu.create(body)
27
+ puts response.body
28
+ ```
26
29
 
27
30
  ## Development
28
31
 
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: utf-8
3
+
4
+ # The MIT License (MIT)
5
+
6
+ # Copyright (c) 2019 Nobuyuki Tanabe
7
+
8
+ # create Consumer object
9
+ require 'hatena_bookmark_client_for_ruby'
10
+ # require 'oauth'
11
+
12
+ USAGE = 'Usage: ruby get_access_token.rb <consumer key> <consumer secret>'
13
+
14
+ SITE_URI = 'https://www.hatena.com'
15
+ REQUEST_TOKEN_URI = '/oauth/initiate?scope=read_public%2Cread_private%2Cwrite_public%2Cwrite_private'
16
+ ACCESS_TOKEN_URI = '/oauth/token'
17
+
18
+ if ARGV.size != 2
19
+ warn USAGE
20
+ exit
21
+ end
22
+
23
+ consumer_key = ARGV[0]
24
+ consumer_secret = ARGV[1]
25
+ consumer = OAuth::Consumer.new(consumer_key, consumer_secret, site: SITE_URI, request_token_url: REQUEST_TOKEN_URI, access_token_url: ACCESS_TOKEN_URI, oauth_callback: 'oob')
26
+
27
+ request_token = consumer.get_request_token
28
+ puts "Visit this website and get the oauth verifier: #{request_token.authorize_url}"
29
+ print 'Enter the oauth verifier:'
30
+
31
+ consumer.options.delete(:oauth_callback)
32
+ oauth_verifier = STDIN.readline.chomp
33
+ access_token = request_token.get_access_token(oauth_verifier: oauth_verifier)
34
+ puts "Access token: #{access_token.token}"
35
+ puts "Access token secret: #{access_token.secret}"
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: utf-8
3
+
4
+ # The MIT License (MIT)
5
+
6
+ # Copyright (c) 2019 Nobuyuki Tanabe
7
+
8
+ # create Consumer object
9
+ # TODO: Should use values obtained from the configuratioin file instead of constants
10
+ USAGE = 'Usage: ruby get_access_token.rb <consumer key> <consumer secret>'
11
+
12
+ SITE_URI = 'https://www.hatena.com'
13
+ REQUEST_TOKEN_URI = '/oauth/initiate?scope=read_public%2Cread_private%2Cwrite_public%2Cwrite_private'
14
+ ACCESS_TOKEN_URI = '/oauth/token'
15
+
16
+ if ARGV.size != 2
17
+ warn USAGE
18
+ exit
19
+ end
20
+
21
+ consumer_key = ARGV[0]
22
+ consumer_secret = ARGV[1]
23
+ consumer = OAuth::Consumer.new(consumer_key,
24
+ consumer_secret,
25
+ site: SITE_URI,
26
+ request_token_url: REQUEST_TOKEN_URI,
27
+ access_token_url: ACCESS_TOKEN_URI,
28
+ oauth_callback: 'oob')
29
+
30
+ request_token = consumer.get_request_token
31
+ puts "Visit this website and get the oauth verifier: #{request_token.authorize_url}"
32
+ print 'Enter the oauth verifier:'
33
+
34
+ consumer.options.delete(:oauth_callback)
35
+ oauth_verifier = STDIN.readline.chomp
36
+ access_token = request_token.get_access_token(oauth_verifier: oauth_verifier)
37
+ puts "Access token: #{access_token.token}"
38
+ puts "Access token secret: #{access_token.secret}"
@@ -4,26 +4,29 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require "hatena_bookmark_client_for_ruby/version"
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "hatena_bookmark_client_for_ruby"
8
- spec.version = HatenaBookmarkClientForRuby::VERSION
9
- spec.authors = ["Nobuyuki Tanabe"]
10
- spec.email = ["tanabe.1478@gmail.com"]
11
-
12
- spec.summary = %q{Hatena Bookmark API Client}
13
- spec.description = %q{API client of Hatena Bookmark for Ruby.}
14
- spec.homepage = "https://github.com/Nabeatsu/hatena_bookmark_client_for_ruby"
15
- spec.license = "MIT"
7
+ spec.name = "hatena_bookmark_client_for_ruby"
8
+ spec.version = HatenaBookmarkClientForRuby::VERSION
9
+ spec.authors = ["Nobuyuki Tanabe"]
10
+ spec.email = ["tanabe.1478@gmail.com"]
16
11
 
12
+ spec.summary = %q{Hatena Bookmark API Client}
13
+ spec.description = %q{API client of Hatena Bookmark for Ruby.}
14
+ spec.homepage = "https://github.com/Nabeatsu/hatena_bookmark_client_for_ruby"
15
+ spec.license = "MIT"
17
16
 
18
17
  # Specify which files should be added to the gem when it is released.
19
18
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
21
20
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
21
  end
23
- spec.bindir = "exe"
24
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
24
  spec.require_paths = ["lib"]
26
25
 
26
+ spec.add_dependency "oauth"
27
+ spec.add_dependency "crack"
28
+ spec.add_dependency "json"
29
+
27
30
  spec.add_development_dependency "bundler", "~> 2.0"
28
31
  spec.add_development_dependency "rake", "~> 10.0"
29
32
  spec.add_development_dependency "rspec", "~> 3.0"
@@ -1,3 +1,3 @@
1
1
  module HatenaBookmarkClientForRuby
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -1,10 +1,103 @@
1
1
  require "hatena_bookmark_client_for_ruby/version"
2
+ require "oauth"
3
+ require "crack"
4
+ require "net/http"
2
5
 
3
6
  module HatenaBookmarkClientForRuby
4
- def self.greet
5
- "Hello"
7
+ class BookmarkCount
8
+ attr_accessor :urls
9
+
10
+ def initialize(urls)
11
+ @urls = urls
12
+ end
13
+
14
+ def get
15
+ uri = URI.parse("http://api.b.st-hatena.com/entry.counts#{query_parameter}")
16
+ response = Net::HTTP.get_response(uri)
17
+ end
18
+
19
+ private
20
+
21
+ def query_parameter
22
+ encoded_urls = urls.map { |url| CGI.escape(url) }
23
+ "?url=#{encoded_urls.join("&url=")}"
24
+ end
25
+ end
26
+
27
+ class Entry
28
+ attr_accessor :url
29
+
30
+ def initialize(url)
31
+ @url = url
32
+ end
33
+
34
+ def get()
35
+ encoded = URI.encode(url)
36
+ uri = URI.parse("http://b.hatena.ne.jp/entry/json/#{url}")
37
+ http = Net::HTTP.new(uri.host, uri.port)
38
+ headers = { "content-Type" => "application/json" }
39
+ http.get(uri.path, headers)
40
+ end
41
+
42
+ def get_withou_relations()
43
+ encoded = URI.encode(url)
44
+ uri = URI.parse("http://b.hatena.ne.jp/entry/jsonlite/#{url}")
45
+ http = Net::HTTP.new(uri.host, uri.port)
46
+ headers = { "content-Type" => "application/json" }
47
+ http.get(uri.path, headers)
48
+ end
49
+ end
50
+
51
+ class Bookmark
52
+ attr_accessor :access_token
53
+
54
+ def initialize(params)
55
+ consumer = OAuth::Consumer.new(
56
+ params[:consumer_key],
57
+ params[:consumer_secret],
58
+ )
59
+
60
+ @access_token = OAuth::AccessToken.new(
61
+ consumer,
62
+ params[:request_token],
63
+ params[:request_secret]
64
+ )
65
+ end
66
+
67
+ def create(params)
68
+ access_token.post("http://api.b.hatena.ne.jp/1/my/bookmark", params)
69
+ end
70
+
71
+ def delete(url)
72
+ encoded_url = CGI::escape(url)
73
+ access_token.delete("http://api.b.hatena.ne.jp/1/my/bookmark?url=#{url}")
74
+ end
75
+
76
+ def get(url)
77
+ encoded_url = CGI::escape(url)
78
+ access_token.get("http://api.b.hatena.ne.jp/1/my/bookmark?url=#{url}")
79
+ end
80
+
81
+ def user_tags()
82
+ access_token.get("http://api.b.hatena.ne.jp/1/my/tags")
83
+ end
84
+
85
+ def entry(url)
86
+ encoded_url = CGI::escape(url)
87
+ access_token.get("http://api.b.hatena.ne.jp/1/entry?url=#{encoded_url}")
88
+ end
89
+
90
+ def user()
91
+ access_token.get("http://api.b.hatena.ne.jp/1/my")
92
+ end
93
+
94
+ def search(id, query, of = 0, limit = 20)
95
+ access_token.get("http://b.hatena.ne.jp/#{id}/search/json?q=#{query.encode("UTF-8")}&of=#{of}&limit=#{limit}")
96
+ end
6
97
  end
7
- class Error < StandardError;
98
+
99
+ class Error < StandardError
8
100
  end
101
+
9
102
  # Your code goes here...
10
103
  end
metadata CHANGED
@@ -1,15 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hatena_bookmark_client_for_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nobuyuki Tanabe
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-04-12 00:00:00.000000000 Z
11
+ date: 2019-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: oauth
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: crack
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: json
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'
13
55
  - !ruby/object:Gem::Dependency
14
56
  name: bundler
15
57
  requirement: !ruby/object:Gem::Requirement
@@ -55,7 +97,8 @@ dependencies:
55
97
  description: API client of Hatena Bookmark for Ruby.
56
98
  email:
57
99
  - tanabe.1478@gmail.com
58
- executables: []
100
+ executables:
101
+ - get_hatebu_access_token
59
102
  extensions: []
60
103
  extra_rdoc_files: []
61
104
  files:
@@ -69,10 +112,11 @@ files:
69
112
  - Rakefile
70
113
  - bin/console
71
114
  - bin/setup
115
+ - exe/get_hatebu_access_token
116
+ - get_access_token.rb
72
117
  - hatena_bookmark_client_for_ruby.gemspec
73
118
  - lib/hatena_bookmark_client_for_ruby.rb
74
119
  - lib/hatena_bookmark_client_for_ruby/version.rb
75
- - shell/exe/sample
76
120
  - vendor/bundle/ruby/2.6.0/bin/htmldiff
77
121
  - vendor/bundle/ruby/2.6.0/bin/ldiff
78
122
  - vendor/bundle/ruby/2.6.0/bin/rake
data/shell/exe/sample DELETED
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'hatena_bookmark_client_for_ruby'
4
-
5
- puts HatenaBookmarkClientForRuby.greet