qiita-sdk 0.1.0
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.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +34 -0
- data/LICENSE.txt +21 -0
- data/README.md +44 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/qiita/sdk.rb +12 -0
- data/lib/qiita/sdk/client.rb +371 -0
- data/lib/qiita/sdk/httpclient.rb +44 -0
- data/lib/qiita/sdk/version.rb +5 -0
- data/qiita-sdk.gemspec +28 -0
- metadata +62 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: ef3399319b6663a45463b626c00587b01e17a82d6dcc659cda6e20ab88b09a86
|
|
4
|
+
data.tar.gz: 102404f6146bdc3e1da5d34aa9888d8a6f1be4eec348c63a56528d0ecb74ec6c
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 637a211f86a0afa7148f5c9411dd088c6bfd425c9495a66310f683959bf1870ee2c8a4cb5d8b07967a1ba982d990210f1ac5430700b3839b259c1dd06acd33f6
|
|
7
|
+
data.tar.gz: b4cccf3edaa50a4e6794d027776ff963da8d63a4e45c7f54e44f10f8e98f6489bd1f1e4a341c486e141bbb90019b81d461d65737b2a52a444f4db7079f92021a
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at yonetani@ataglance.co.jp. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: https://contributor-covenant.org
|
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
qiita-sdk (0.1.0)
|
|
5
|
+
|
|
6
|
+
GEM
|
|
7
|
+
remote: https://rubygems.org/
|
|
8
|
+
specs:
|
|
9
|
+
diff-lcs (1.4.4)
|
|
10
|
+
rake (12.3.3)
|
|
11
|
+
rspec (3.9.0)
|
|
12
|
+
rspec-core (~> 3.9.0)
|
|
13
|
+
rspec-expectations (~> 3.9.0)
|
|
14
|
+
rspec-mocks (~> 3.9.0)
|
|
15
|
+
rspec-core (3.9.2)
|
|
16
|
+
rspec-support (~> 3.9.3)
|
|
17
|
+
rspec-expectations (3.9.2)
|
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
19
|
+
rspec-support (~> 3.9.0)
|
|
20
|
+
rspec-mocks (3.9.1)
|
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
22
|
+
rspec-support (~> 3.9.0)
|
|
23
|
+
rspec-support (3.9.3)
|
|
24
|
+
|
|
25
|
+
PLATFORMS
|
|
26
|
+
ruby
|
|
27
|
+
|
|
28
|
+
DEPENDENCIES
|
|
29
|
+
qiita-sdk!
|
|
30
|
+
rake (~> 12.0)
|
|
31
|
+
rspec (~> 3.0)
|
|
32
|
+
|
|
33
|
+
BUNDLED WITH
|
|
34
|
+
2.1.4
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 yonetani
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Qiita::Sdk
|
|
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/qiita/sdk`. 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
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add this line to your application's Gemfile:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem 'qiita-sdk'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
And then execute:
|
|
16
|
+
|
|
17
|
+
$ bundle install
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
$ gem install qiita-sdk
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
TODO: Write usage instructions here
|
|
26
|
+
|
|
27
|
+
## Development
|
|
28
|
+
|
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
30
|
+
|
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
32
|
+
|
|
33
|
+
## Contributing
|
|
34
|
+
|
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/qiita-sdk. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/qiita-sdk/blob/master/CODE_OF_CONDUCT.md).
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
## License
|
|
39
|
+
|
|
40
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
41
|
+
|
|
42
|
+
## Code of Conduct
|
|
43
|
+
|
|
44
|
+
Everyone interacting in the Qiita::Sdk project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/qiita-sdk/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "qiita/sdk"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/qiita/sdk.rb
ADDED
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
module Qiita
|
|
2
|
+
module Sdk
|
|
3
|
+
class Client
|
|
4
|
+
require 'net/https'
|
|
5
|
+
require 'uri'
|
|
6
|
+
require 'json'
|
|
7
|
+
|
|
8
|
+
API_BASE_URL = 'https://qiita.com'
|
|
9
|
+
|
|
10
|
+
DEFAULT_HEADERS = {
|
|
11
|
+
"Accept" => "application/json",
|
|
12
|
+
"Content-Type" => "application/json"
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
def initialize(access_token: nil)
|
|
16
|
+
@access_token = access_token
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def default_headers
|
|
20
|
+
headers = DEFAULT_HEADERS.clone
|
|
21
|
+
headers["Authorization"] = "Bearer #{@access_token}" if @access_token
|
|
22
|
+
headers
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def get(url)
|
|
26
|
+
httpclient = HTTPClient.new
|
|
27
|
+
httpclient.get(url, default_headers)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def patch(url, params)
|
|
31
|
+
httpclient = HTTPClient.new
|
|
32
|
+
httpclient.patch(url, params.to_json, default_headers)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def put(url)
|
|
36
|
+
httpclient = HTTPClient.new
|
|
37
|
+
httpclient.put(url)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def post(url, params)
|
|
41
|
+
httpclient = HTTPClient.new
|
|
42
|
+
httpclient.post(url, params.to_json, default_headers)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def delete(url)
|
|
46
|
+
httpclient = HTTPClient.new
|
|
47
|
+
httpclient.delete(url)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# 全てのユーザの一覧
|
|
51
|
+
def fetch_users
|
|
52
|
+
path = '/api/v2/users'
|
|
53
|
+
url = API_BASE_URL + path
|
|
54
|
+
|
|
55
|
+
get(url)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# 記事につけられた「LGTM!」一覧
|
|
59
|
+
def fetch_item_likes(item_id:)
|
|
60
|
+
path = "/api/v2/items/#{item_id}/likes"
|
|
61
|
+
url = API_BASE_URL + path
|
|
62
|
+
|
|
63
|
+
get(url)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# コメントを削除
|
|
67
|
+
def delete_comment(comment_id:)
|
|
68
|
+
path = "/api/v2/comments/#{comment_id}"
|
|
69
|
+
url = API_BASE_URL + path
|
|
70
|
+
|
|
71
|
+
delete(url)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# コメントを取得
|
|
75
|
+
def fetch_comment(comment_id:)
|
|
76
|
+
path = "/api/v2/comments/#{comment_id}"
|
|
77
|
+
url = API_BASE_URL + path
|
|
78
|
+
|
|
79
|
+
get(url)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# コメントを更新
|
|
83
|
+
def update_comment(comment_id:, body:)
|
|
84
|
+
path = "/api/v2/comments/#{comment_id}"
|
|
85
|
+
url = API_BASE_URL + path
|
|
86
|
+
|
|
87
|
+
params = {
|
|
88
|
+
body: body
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
patch(url, params)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# 投稿に付けられたコメント一覧
|
|
95
|
+
def fetch_item_comments(item_id:)
|
|
96
|
+
path = "/api/v2/items/#{item_id}/comments"
|
|
97
|
+
url = API_BASE_URL + path
|
|
98
|
+
|
|
99
|
+
get(url)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# 記事に対してコメントを投稿
|
|
103
|
+
def post_comment(item_id:, body:)
|
|
104
|
+
path = "/api/v2/items/#{item_id}/comments"
|
|
105
|
+
url = API_BASE_URL + path
|
|
106
|
+
|
|
107
|
+
params = {
|
|
108
|
+
body: body
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
post(url, params)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
# タグを取得
|
|
115
|
+
def fetch_tag(tag_id:)
|
|
116
|
+
path = "/api/v2/tags/#{tag_id}"
|
|
117
|
+
url = API_BASE_URL + path
|
|
118
|
+
|
|
119
|
+
get(url)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# ユーザがフォローしているタグ一覧
|
|
123
|
+
def fetch_following_tags(user_id:)
|
|
124
|
+
path = "/api/v2/users/#{user_id}/following_tags"
|
|
125
|
+
url = API_BASE_URL + path
|
|
126
|
+
|
|
127
|
+
get(url)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# タグのフォローを外す
|
|
131
|
+
def delete_following(tag_id:)
|
|
132
|
+
path = "/api/v2/tags/#{tag_id}/following"
|
|
133
|
+
url = API_BASE_URL + path
|
|
134
|
+
|
|
135
|
+
delete(url)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# タグをフォローしているかどうかを調る
|
|
139
|
+
def check_tag_following(tag_id:)
|
|
140
|
+
path = "/api/v2/tags/#{tag_id}/following"
|
|
141
|
+
url = API_BASE_URL + path
|
|
142
|
+
|
|
143
|
+
get(url)
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# タグをフォロー
|
|
147
|
+
def follow_tag(tag_id:)
|
|
148
|
+
path = "/api/v2/tags/#{tag_id}/following"
|
|
149
|
+
url = API_BASE_URL + path
|
|
150
|
+
|
|
151
|
+
put(url)
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
# 記事をストックしているユーザ一覧を、ストックした日時の降順で返す
|
|
155
|
+
def fetch_item_stockers(item_id:)
|
|
156
|
+
path = "/api/v2/items/#{item_id}/stockers"
|
|
157
|
+
url = API_BASE_URL + path
|
|
158
|
+
|
|
159
|
+
get(url)
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
# 全てのユーザの一覧を作成日時の降順で取得
|
|
163
|
+
def fetch_users
|
|
164
|
+
path = "/api/v2/users"
|
|
165
|
+
url = API_BASE_URL + path
|
|
166
|
+
|
|
167
|
+
get(url)
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
# ユーザを取得
|
|
171
|
+
def fetch_user(user_id:)
|
|
172
|
+
path = "/api/v2/users/#{user_id}"
|
|
173
|
+
url = API_BASE_URL + path
|
|
174
|
+
|
|
175
|
+
get(url)
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
# ユーザがフォローしているユーザ一覧を取得
|
|
179
|
+
def fetch_followees(user_id:)
|
|
180
|
+
path = "/api/v2/users/#{user_id}/followees"
|
|
181
|
+
url = API_BASE_URL + path
|
|
182
|
+
|
|
183
|
+
get(url)
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
# ユーザをフォローしているユーザ一覧を取得
|
|
187
|
+
def fetch_followers(user_id:)
|
|
188
|
+
path = "/api/v2/users/#{user_id}/followers"
|
|
189
|
+
url = API_BASE_URL + path
|
|
190
|
+
|
|
191
|
+
get(url)
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
# ユーザへのフォローを外します。
|
|
195
|
+
def delete_following(user_id:)
|
|
196
|
+
path = "/api/v2/users/#{user_id}/following"
|
|
197
|
+
url = API_BASE_URL + path
|
|
198
|
+
|
|
199
|
+
delete(url)
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
# ユーザをフォローしている場合に204を返す
|
|
203
|
+
def check_following(user_id:)
|
|
204
|
+
path = "/api/v2/users/#{user_id}/following"
|
|
205
|
+
url = API_BASE_URL + path
|
|
206
|
+
|
|
207
|
+
get(url)
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
# ユーザをフォロー
|
|
211
|
+
def follow_user(user_id:)
|
|
212
|
+
path = "/api/v2/users/#{user_id}/following"
|
|
213
|
+
url = API_BASE_URL + path
|
|
214
|
+
|
|
215
|
+
put(url)
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
# 認証中のユーザの記事の一覧を作成日時の降順で返す
|
|
219
|
+
def fetch_my_items
|
|
220
|
+
path = "/api/v2/authenticated_user/items"
|
|
221
|
+
url = API_BASE_URL + path
|
|
222
|
+
|
|
223
|
+
get(url)
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
# 記事の一覧を作成日時の降順で返す
|
|
227
|
+
def fetch_items
|
|
228
|
+
path = '/api/v2/items'
|
|
229
|
+
url = API_BASE_URL + path
|
|
230
|
+
|
|
231
|
+
get(url)
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
# 新たに記事を作成
|
|
235
|
+
def post_item(params:)
|
|
236
|
+
path = "/api/v2/items"
|
|
237
|
+
url = API_BASE_URL + path
|
|
238
|
+
|
|
239
|
+
post(url, params)
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
# 記事を削除
|
|
243
|
+
def delete_item(item_id:)
|
|
244
|
+
path = "/api/v2/items/#{item_id}"
|
|
245
|
+
url = API_BASE_URL + path
|
|
246
|
+
|
|
247
|
+
delete(url)
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
# 記事を取得
|
|
251
|
+
def fetch_item(item_id:)
|
|
252
|
+
path = "/api/v2/items/#{item_id}"
|
|
253
|
+
url = API_BASE_URL + path
|
|
254
|
+
|
|
255
|
+
get(url)
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
# 記事を更新
|
|
259
|
+
def update_item(item_id:, params:)
|
|
260
|
+
path = "/api/v2/items/#{item_id}"
|
|
261
|
+
url = API_BASE_URL + path
|
|
262
|
+
|
|
263
|
+
patch(url, params)
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
# 記事をストック
|
|
267
|
+
def stock_item(item_id:)
|
|
268
|
+
path = "/api/v2/items/#{item_id}"
|
|
269
|
+
url = API_BASE_URL + path
|
|
270
|
+
|
|
271
|
+
put(url)
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
# 記事をストックから取り除く
|
|
275
|
+
def delete_stock(item_id:)
|
|
276
|
+
path = "/api/v2/items/#{item_id}"
|
|
277
|
+
url = API_BASE_URL + path
|
|
278
|
+
|
|
279
|
+
delete(url)
|
|
280
|
+
end
|
|
281
|
+
|
|
282
|
+
# 記事をストックしているかどうか調べる
|
|
283
|
+
def check_item_stock(item_id:)
|
|
284
|
+
path = "/api/v2/items/#{item_id}/stock"
|
|
285
|
+
url = API_BASE_URL + path
|
|
286
|
+
|
|
287
|
+
get(url)
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
# タグの記事一覧
|
|
291
|
+
def fetch_tag_items(tag_id:)
|
|
292
|
+
path = "/api/v2/tags/#{tag_id}/items"
|
|
293
|
+
url = API_BASE_URL + path
|
|
294
|
+
|
|
295
|
+
get(url)
|
|
296
|
+
end
|
|
297
|
+
|
|
298
|
+
# 指定されたユーザの記事一覧
|
|
299
|
+
def fetch_user_items(user_id:)
|
|
300
|
+
path = "/api/v2/tags/#{user_id}/items"
|
|
301
|
+
url = API_BASE_URL + path
|
|
302
|
+
|
|
303
|
+
get(url)
|
|
304
|
+
end
|
|
305
|
+
|
|
306
|
+
# 指定されたユーザがストックした記事一覧
|
|
307
|
+
def fetch_user_stocks(user_id:)
|
|
308
|
+
path = "/api/v2/users/#{user_id}/stocks"
|
|
309
|
+
url = API_BASE_URL + path
|
|
310
|
+
|
|
311
|
+
get(url)
|
|
312
|
+
end
|
|
313
|
+
|
|
314
|
+
# コメントに絵文字リアクションを付ける
|
|
315
|
+
def attach_reaction_to_comment(comment_id:, params)
|
|
316
|
+
path = "/api/v2/comments/#{comment_id}/reactions"
|
|
317
|
+
url = API_BASE_URL + path
|
|
318
|
+
|
|
319
|
+
post(url, params)
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
# 記事に絵文字リアクションを付ける
|
|
323
|
+
def attach_reaction_to_item(item_id: params)
|
|
324
|
+
path = "/api/v2/items/#{item_id}/reactions"
|
|
325
|
+
url = API_BASE_URL + path
|
|
326
|
+
|
|
327
|
+
post(url, params)
|
|
328
|
+
end
|
|
329
|
+
|
|
330
|
+
# コメントから絵文字リアクションを削除
|
|
331
|
+
def delete_comment_reaction(comment_id:, reaction_name:)
|
|
332
|
+
path = "/api/v2/comments/#{comment_id}/reactions/#{reaction_name}"
|
|
333
|
+
url = API_BASE_URL + path
|
|
334
|
+
|
|
335
|
+
delete(url)
|
|
336
|
+
end
|
|
337
|
+
|
|
338
|
+
# 記事から絵文字リアクションを削除
|
|
339
|
+
def delete_item_reaction(item_id:, reaction_name:)
|
|
340
|
+
path = "/api/v2/items/#{item_id}/reactions/#{reaction_name}"
|
|
341
|
+
url = API_BASE_URL + path
|
|
342
|
+
|
|
343
|
+
delete(url)
|
|
344
|
+
end
|
|
345
|
+
|
|
346
|
+
# コメントに付けられた絵文字リアクション一覧
|
|
347
|
+
def fetch_comment_reactions(comment_id:)
|
|
348
|
+
path = "/api/v2/comments/#{comment_id}/reactions"
|
|
349
|
+
url = API_BASE_URL + path
|
|
350
|
+
|
|
351
|
+
get(url)
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
# 記事に付けられた絵文字リアクション一覧
|
|
355
|
+
def fetch_item_reactions(item_id:)
|
|
356
|
+
path = "/api/v2/items/#{item_id}/reactions"
|
|
357
|
+
url = API_BASE_URL + path
|
|
358
|
+
|
|
359
|
+
get(url)
|
|
360
|
+
end
|
|
361
|
+
|
|
362
|
+
# アクセストークンに紐付いたユーザを返す
|
|
363
|
+
def fetch_authenticated_user
|
|
364
|
+
path = "/api/v2/authenticated_user"
|
|
365
|
+
url = API_BASE_URL + path
|
|
366
|
+
|
|
367
|
+
get(url)
|
|
368
|
+
end
|
|
369
|
+
end
|
|
370
|
+
end
|
|
371
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
module Qiita
|
|
2
|
+
module Sdk
|
|
3
|
+
class HTTPClient
|
|
4
|
+
require 'net/https'
|
|
5
|
+
require 'uri'
|
|
6
|
+
require 'json'
|
|
7
|
+
|
|
8
|
+
# 'https://qiita.com/api/v2/users'
|
|
9
|
+
def net_http(uri)
|
|
10
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
11
|
+
http.use_ssl = true
|
|
12
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
13
|
+
http
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def get(url, header = {})
|
|
17
|
+
uri = URI.parse(url)
|
|
18
|
+
|
|
19
|
+
net_http(uri).get(uri.request_uri, header)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def post(url, params, header = {})
|
|
23
|
+
uri = URI.parse(url)
|
|
24
|
+
net_http(uri).post(uri.request_uri, params, header)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def delete(url, header = {})
|
|
28
|
+
uri = URI.parse(url)
|
|
29
|
+
net_http(uri).delete(uri.request_uri, header)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def patch(url, params, header = {})
|
|
33
|
+
uri = URI.parse(url)
|
|
34
|
+
net_http(uri).patch(uri.request_uri, params, header)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def put(url, params, header = {})
|
|
38
|
+
uri = URI.parse(url)
|
|
39
|
+
net_http(uri).put(uri.request_uri, params, header)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
data/qiita-sdk.gemspec
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require_relative 'lib/qiita/sdk/version'
|
|
2
|
+
|
|
3
|
+
Gem::Specification.new do |spec|
|
|
4
|
+
spec.name = "qiita-sdk"
|
|
5
|
+
spec.version = Qiita::Sdk::VERSION
|
|
6
|
+
spec.authors = ["yonetani"]
|
|
7
|
+
spec.email = ["sbkn0919@gmail.com"]
|
|
8
|
+
|
|
9
|
+
spec.summary = %q{qiita sdk}
|
|
10
|
+
spec.description = %q{qiita sdk}
|
|
11
|
+
spec.homepage = "http://example.com/"
|
|
12
|
+
spec.license = "MIT"
|
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
17
|
+
spec.metadata["source_code_uri"] = "http://example.com/"
|
|
18
|
+
spec.metadata["changelog_uri"] = "http://example.com/"
|
|
19
|
+
|
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
22
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
24
|
+
end
|
|
25
|
+
spec.bindir = "exe"
|
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
27
|
+
spec.require_paths = ["lib"]
|
|
28
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: qiita-sdk
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- yonetani
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2020-08-26 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: qiita sdk
|
|
14
|
+
email:
|
|
15
|
+
- sbkn0919@gmail.com
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- ".gitignore"
|
|
21
|
+
- ".rspec"
|
|
22
|
+
- ".travis.yml"
|
|
23
|
+
- CODE_OF_CONDUCT.md
|
|
24
|
+
- Gemfile
|
|
25
|
+
- Gemfile.lock
|
|
26
|
+
- LICENSE.txt
|
|
27
|
+
- README.md
|
|
28
|
+
- Rakefile
|
|
29
|
+
- bin/console
|
|
30
|
+
- bin/setup
|
|
31
|
+
- lib/qiita/sdk.rb
|
|
32
|
+
- lib/qiita/sdk/client.rb
|
|
33
|
+
- lib/qiita/sdk/httpclient.rb
|
|
34
|
+
- lib/qiita/sdk/version.rb
|
|
35
|
+
- qiita-sdk.gemspec
|
|
36
|
+
homepage: http://example.com/
|
|
37
|
+
licenses:
|
|
38
|
+
- MIT
|
|
39
|
+
metadata:
|
|
40
|
+
homepage_uri: http://example.com/
|
|
41
|
+
source_code_uri: http://example.com/
|
|
42
|
+
changelog_uri: http://example.com/
|
|
43
|
+
post_install_message:
|
|
44
|
+
rdoc_options: []
|
|
45
|
+
require_paths:
|
|
46
|
+
- lib
|
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
48
|
+
requirements:
|
|
49
|
+
- - ">="
|
|
50
|
+
- !ruby/object:Gem::Version
|
|
51
|
+
version: 2.3.0
|
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
|
+
requirements:
|
|
54
|
+
- - ">="
|
|
55
|
+
- !ruby/object:Gem::Version
|
|
56
|
+
version: '0'
|
|
57
|
+
requirements: []
|
|
58
|
+
rubygems_version: 3.0.3
|
|
59
|
+
signing_key:
|
|
60
|
+
specification_version: 4
|
|
61
|
+
summary: qiita sdk
|
|
62
|
+
test_files: []
|