qiitan 0.0.3

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: 1172f24476638d81b933e79f2ade88ce5e54b081
4
+ data.tar.gz: b6abdf52afd3ba4ae992dbf1fea40a7dbb2e126d
5
+ SHA512:
6
+ metadata.gz: 6b78b4d4cbcce81d0782188368d11b4b7118e1f48156ea6003db97b88a8e36bc4e59b9ceb8f4eb1916968ebf5be814a6e719b606ae6a666f6d0102403bb1d581
7
+ data.tar.gz: 56f44fd5ac0c0191a30ed8751de74b6d7be6a0868fb25c3e59196f35642649f0218b9432e7837059f35bc75b9006917dbcef3ec1bc61a4b950c7cb3a06313154
@@ -0,0 +1,25 @@
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
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+
24
+ *.swp
25
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in qiitan.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 akihiro
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,29 @@
1
+ # Qiitan
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'qiitan'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install qiitan
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/qiitan/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task default: [:spec]
4
+ begin
5
+ require 'rspec/core/rake_task'
6
+ RSpec::Core::RakeTask.new(:spec) do |spec|
7
+ spec.pattern = 'spec/**/*_spec.rb'
8
+ spec.rspec_opts = ['-cfs']
9
+ end
10
+ #rescue LoadError => e
11
+ end
@@ -0,0 +1,78 @@
1
+ require "qiitan/version"
2
+ require 'net/http'
3
+ require 'uri'
4
+ require 'json'
5
+ require 'qiitan/api/users'
6
+ require 'qiitan/api/items'
7
+ require 'qiitan/api/tags'
8
+
9
+ module Qiitan
10
+ API_BASE_URL = 'https://qiita.com/api/v1/'
11
+
12
+ module HTTP
13
+ def self.request(url, http_method, use_ssl = false)
14
+ uri = URI.parse url
15
+
16
+ case http_method
17
+ when :get then
18
+ req = Net::HTTP::Get.new uri.request_uri
19
+ when :post then
20
+ req = Net::HTTP::Post.new uri.request_uri
21
+ when :put then
22
+ req = Net::HTTP::Put.new uri.request_uri
23
+ when :delete then
24
+ req = Net::HTTP::Delete.new uri.request_uri
25
+ end
26
+
27
+ yield req if block_given?
28
+
29
+ http = Net::HTTP.new uri.host, uri.port
30
+ #http.set_debug_output($stderr)
31
+ http.use_ssl = use_ssl
32
+ res = http.request req
33
+
34
+ #2xx系のコードか否かを判定
35
+ #レスポンスの内容チェックは行わない
36
+ if res.kind_of? Net::HTTPSuccess then
37
+ res
38
+ else
39
+ raise 'HTTP Request Failed.'
40
+ end
41
+ end
42
+ end
43
+
44
+ #ToDo 増えすぎたメソッドはModuleで分割する予定
45
+ class Client
46
+ include Qiitan::API::Users
47
+ include Qiitan::API::Items
48
+ include Qiitan::API::Tags
49
+ attr_reader :token
50
+
51
+ =begin rdoc
52
+ ==== Args
53
+ url_name passwordをキーにしたハッシュを指定する
54
+ ==== Raise
55
+ RuntimeError
56
+ =end
57
+ def initialize(account)
58
+ url = "#{API_BASE_URL}auth"
59
+ res = Qiitan::HTTP.request(url, :post, true) do |req|
60
+ req.set_form_data account
61
+ end
62
+
63
+ hashed = JSON.parse res.body
64
+
65
+ raise 'auth error. check youre username and password' if hashed.key? 'error'
66
+ @token = hashed['token']
67
+ end
68
+
69
+ =begin
70
+ このメソッドを実行することで、APIの残りリクエスト数を取得することが出来る
71
+ =end
72
+ def rate_limit
73
+ url = "#{API_BASE_URL}rate_limit?token=#{@token}"
74
+ res = Qiitan::HTTP.request(url, :get, true)
75
+ JSON.parse res.body
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,31 @@
1
+ module Qiitan
2
+ module API
3
+ module Items
4
+ =begin
5
+ ==== Args
6
+ Hash
7
+ =end
8
+ def post(payload)
9
+ url = "#{API_BASE_URL}items?token=#{@token}"
10
+ res = Qiitan::HTTP.request(url, :post, true) do |req|
11
+ req['Content-Type'] = 'application/json'
12
+ req.body = payload
13
+ end
14
+
15
+ JSON.parse res.body
16
+ end
17
+
18
+ def delete
19
+ url = "#{API_BASE_URL}items/#{uuid}?token=#{@token}"
20
+ res = Qiitan::HTTP.request(url, :delete, true)
21
+ end
22
+
23
+ def get_newly_post
24
+ url = "#{API_BASE_URL}items?token=#{@token}"
25
+ res = Qiitan::HTTP.request(url, :get, true)
26
+
27
+ JSON.parse res.body
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,14 @@
1
+ module Qiitan
2
+ module API
3
+ module Tags
4
+ =begin
5
+ Qiitaにて使用されているタグを取得する
6
+ =end
7
+ def tags_list
8
+ url = "#{API_BASE_URL}tags?token=#{@token}"
9
+ res = Qiitan::HTTP.request(url, :get, true)
10
+ JSON.parse res.body
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,48 @@
1
+ module Qiitan
2
+ module API
3
+ module Users
4
+ =begin
5
+ ログインしているユーザーの情報をHashにて返す
6
+ =end
7
+ def get_user_info
8
+ url = "#{API_BASE_URL}user?token=#{@token}"
9
+ res = Qiitan::HTTP.request(url, :get, true)
10
+ JSON.parse res.body
11
+ end
12
+ =begin
13
+ 取得したいユーザー名を指定します
14
+ =end
15
+ def get_users_info(url_name)
16
+ url = "#{API_BASE_URL}users#{url_name}?token=#{@token}"
17
+ res = Qiitan::HTTP.request(url, :get, true)
18
+ JSON.parse res.body
19
+ end
20
+ =begin
21
+ ユーザー名を指定することで、その人が投稿した記事を取得することが出来ます
22
+ =end
23
+ def posted_by(url_name)
24
+ url = "#{API_BASE_URL}users/#{url_name}/items?token=#{@token}"
25
+ res = Qiitan::HTTP.request(url, :get, true)
26
+ JSON.parse res.body
27
+ end
28
+
29
+ =begin
30
+ ユーザー名を指定することで、その人がストックした記事の一覧を取得することが出来ます
31
+ =end
32
+ def stocked_by(url_name)
33
+ url = "#{API_BASE_URL}users/#{url_name}/items"
34
+ res = Qiitan::HTTP.request(url, :get, true)
35
+ JSON.parse res.body
36
+ end
37
+
38
+ =begin
39
+ 自身がストックした記事の一覧を取得出来ます
40
+ =end
41
+ def stocked
42
+ url = "#{API_BASE_URL}stocks?token=#{@token}"
43
+ res = Qiitan::HTTP.request(url, :get, true)
44
+ JSON.parse res.body
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,3 @@
1
+ module Qiitan
2
+ VERSION = "0.0.3"
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'qiitan/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "qiitan"
8
+ spec.version = Qiitan::VERSION
9
+ spec.authors = ["akihiro"]
10
+ spec.email = ["cp2xlrun@gmail.com"]
11
+ spec.summary = %q{qiita api wrapper}
12
+ spec.description = %q{simple wrapper library for qiita api}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec", "2.14.1"
24
+ end
@@ -0,0 +1,82 @@
1
+ require 'qiitan'
2
+
3
+ describe Qiitan do
4
+ describe Qiitan::Client do
5
+ describe "new" do
6
+ context "トークンの取得に成功すると" do
7
+ it 'clientインスタンスが生成される' do
8
+ client = Qiitan::Client.new({url_name:'foo', password: 'atraptilandroin'})
9
+ expect(client).to be_an_instance_of Qiitan::Client
10
+ end
11
+ end
12
+
13
+ context "トークンの取得に失敗すると" do
14
+ it '例外が投げられる' do
15
+ expect do
16
+ client = Qiitan::Client.new({url_name:'foo', password: ''})
17
+ end.to raise_error(RuntimeError)
18
+ end
19
+ end
20
+ end
21
+
22
+ before do
23
+ @client = Qiitan::Client.new({url_name:'foo', password: 'atraptilandroin'})
24
+ end
25
+
26
+ describe "#rate_limit" do
27
+ context "正常に完了すると" do
28
+ it "残りアクセス数がハッシュで返される" do
29
+ expect(@client.rate_limit).to be_an_instance_of Hash
30
+ end
31
+ end
32
+ end
33
+
34
+ describe "#get_user_info" do
35
+ context "正常に完了" do
36
+ it "ログインしているユーザーの情報をハッシュで返す" do
37
+ expect(@client.get_user_info).to be_an_instance_of Hash
38
+ end
39
+ end
40
+ end
41
+
42
+ describe "#post" do
43
+ context "正常に完了" do
44
+ it "投稿結果がハッシュで返される" do
45
+ item = {
46
+ 'title' => 'from qiitan',
47
+ 'tags' => [
48
+ {'name' => 'test'}
49
+ ],
50
+ 'body' => 'this post from qiitan',
51
+ 'private' => true
52
+ }.to_json
53
+ expect(@client.post(item)).to be_an_instance_of Hash
54
+ end
55
+ end
56
+ end
57
+
58
+ describe "#tags_list" do
59
+ context "正常に完了" do
60
+ it "タグの一覧を配列で返す" do
61
+ expect(@client.tags_list).to be_an_instance_of Array
62
+ end
63
+ end
64
+ end
65
+
66
+ describe "#get_newly_post" do
67
+ context "正常に取得した場合" do
68
+ it "最新の投稿を配列で返す" do
69
+ expect(@client.get_newly_post).to be_an_instance_of Array
70
+ end
71
+ end
72
+ end
73
+
74
+ describe "#stocked" do
75
+ context "正常に取得出来た場合" do
76
+ it "ストックした投稿を配列で返す" do
77
+ expect(@client.stocked).to be_an_instance_of Array
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: qiitan
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - akihiro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 2.14.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 2.14.1
55
+ description: simple wrapper library for qiita api
56
+ email:
57
+ - cp2xlrun@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/qiitan.rb
68
+ - lib/qiitan/api/items.rb
69
+ - lib/qiitan/api/tags.rb
70
+ - lib/qiitan/api/users.rb
71
+ - lib/qiitan/version.rb
72
+ - qiitan.gemspec
73
+ - spec/qiitan_spec.rb
74
+ homepage: ''
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.0.14
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: qiita api wrapper
98
+ test_files:
99
+ - spec/qiitan_spec.rb