line-social 0.1.2 → 1.0.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 +4 -4
- data/.travis.yml +11 -0
- data/Gemfile.lock +1 -1
- data/README.md +36 -3
- data/lib/line/social/client.rb +4 -8
- data/lib/line/social/friendship.rb +9 -0
- data/lib/line/social/oauth.rb +34 -3
- data/lib/line/social/profile.rb +2 -2
- data/lib/line/social/request/base.rb +1 -1
- data/lib/line/social/request/friendship.rb +17 -5
- data/lib/line/social/request/oauth.rb +54 -12
- data/lib/line/social/request/profile.rb +5 -9
- data/lib/line/social/version.rb +1 -1
- data/lib/line/social.rb +1 -0
- data/line-social.gemspec +2 -2
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bddb24a7a0f87bbfb1c0da8cace65bc2fbeff831aeeed14302b36475d7b740ac
|
4
|
+
data.tar.gz: 97cc163c482394a8dfb20742dcf712c289637f50e9c4a3489f03cf699c9da485
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3a14f639e1731790ebcc7943132575e202aea638c57d938264bf364eb2191e0a35538963e994719909fe0ec230ccc932764eb345fa876059ab7574881ef9b66
|
7
|
+
data.tar.gz: 7e9aaf92b9c30dcb75a041f176f52a6b6083f9980b00d212e07fd8364ca3e05a3a56ea8f9a6cd1e07479ad9b9bdf69072501fb5ca8cd5375016176d25c1d465e
|
data/.travis.yml
CHANGED
@@ -1,7 +1,18 @@
|
|
1
1
|
---
|
2
|
+
env:
|
3
|
+
global:
|
4
|
+
- CC_TEST_REPORTER_ID=0ab187cf7121ad5639538a6149e230fc8a176c58f1932a123eb877c8775c8e84
|
2
5
|
sudo: false
|
3
6
|
language: ruby
|
4
7
|
cache: bundler
|
5
8
|
rvm:
|
6
9
|
- 2.6.2
|
7
10
|
before_install: gem install bundler -v 2.0.1
|
11
|
+
before_script:
|
12
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
13
|
+
- chmod +x ./cc-test-reporter
|
14
|
+
- ./cc-test-reporter before-build
|
15
|
+
script:
|
16
|
+
- bundle exec rspec
|
17
|
+
after_script:
|
18
|
+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# Line::Social
|
2
2
|
|
3
|
-
|
3
|
+
[](https://travis-ci.org/camelmasa/line-social)
|
4
|
+
[](https://codeclimate.com/github/camelmasa/line-social/maintainability)
|
5
|
+
[](https://codeclimate.com/github/camelmasa/line-social/test_coverage)
|
4
6
|
|
5
|
-
|
7
|
+
Ruby client for [LINE Social API](https://developers.line.biz/en/reference/social-api/).
|
6
8
|
|
7
9
|
## Installation
|
8
10
|
|
@@ -22,7 +24,38 @@ Or install it yourself as:
|
|
22
24
|
|
23
25
|
## Usage
|
24
26
|
|
25
|
-
|
27
|
+
```ruby
|
28
|
+
require "line/social"
|
29
|
+
client = Line::Social::Client.new
|
30
|
+
|
31
|
+
|
32
|
+
# Oauth
|
33
|
+
|
34
|
+
## issue
|
35
|
+
oauth_client = client.oauth(client_id: "YOUR_CLIENT_ID", client_secret: "YOUR_CLIENT_SECRET")
|
36
|
+
oauth = oauth_client.issue(code: "YOUR_CODE", redirect_uri: "YOUR_REDIRECT_URI")
|
37
|
+
|
38
|
+
## verify
|
39
|
+
oauth_client.verify(oauth.access_token) # or oauth.verify!
|
40
|
+
|
41
|
+
## refresh
|
42
|
+
oauth_client.refresh(oauth.refresh_token) # or oauth.refresh!
|
43
|
+
|
44
|
+
## revoke
|
45
|
+
oauth_client.revoke(oauth.access_token) # or oauth.revoke!
|
46
|
+
|
47
|
+
|
48
|
+
# Friendship
|
49
|
+
|
50
|
+
## get
|
51
|
+
client.friendship.get(oauth.access_token)
|
52
|
+
|
53
|
+
|
54
|
+
# Profile
|
55
|
+
|
56
|
+
## get
|
57
|
+
client.profile.get(oauth.access_token)
|
58
|
+
```
|
26
59
|
|
27
60
|
## Development
|
28
61
|
|
data/lib/line/social/client.rb
CHANGED
@@ -1,20 +1,16 @@
|
|
1
1
|
module Line
|
2
2
|
module Social
|
3
3
|
class Client
|
4
|
-
def initialize(access_token)
|
5
|
-
@access_token = access_token
|
6
|
-
end
|
7
|
-
|
8
4
|
def friendship
|
9
|
-
Request::Friendship.new
|
5
|
+
Request::Friendship.new
|
10
6
|
end
|
11
7
|
|
12
|
-
def oauth
|
13
|
-
Request::Oauth.new(
|
8
|
+
def oauth(client_id:, client_secret:)
|
9
|
+
Request::Oauth.new(client_id: client_id, client_secret: client_secret)
|
14
10
|
end
|
15
11
|
|
16
12
|
def profile
|
17
|
-
Request::Profile.new
|
13
|
+
Request::Profile.new
|
18
14
|
end
|
19
15
|
end
|
20
16
|
end
|
data/lib/line/social/oauth.rb
CHANGED
@@ -3,9 +3,40 @@ module Line
|
|
3
3
|
class Oauth
|
4
4
|
include Virtus.model(strict: true)
|
5
5
|
|
6
|
-
attribute :
|
7
|
-
attribute :client_id,
|
8
|
-
attribute :
|
6
|
+
attribute :access_token, String, required: false
|
7
|
+
attribute :client_id, String
|
8
|
+
attribute :client_secret, String
|
9
|
+
attribute :expires_in, Integer
|
10
|
+
attribute :id_token, String, required: false
|
11
|
+
attribute :refresh_token, String, required: false
|
12
|
+
attribute :scope, String
|
13
|
+
attribute :token_type, String, required: false
|
14
|
+
|
15
|
+
def verify!
|
16
|
+
oauth = client.verify(access_token)
|
17
|
+
self.expires_in = oauth.expires_in
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
def refresh!
|
22
|
+
oauth = client.refresh(refresh_token)
|
23
|
+
self.access_token = oauth.access_token
|
24
|
+
self.expires_in = oauth.expires_in
|
25
|
+
self.id_token = oauth.id_token
|
26
|
+
self.refresh_token = oauth.refresh_token
|
27
|
+
self
|
28
|
+
end
|
29
|
+
|
30
|
+
def revoke!
|
31
|
+
client.revoke(access_token)
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def client
|
38
|
+
Request::Oauth.new(client_id: client_id, client_secret: client_secret)
|
39
|
+
end
|
9
40
|
end
|
10
41
|
end
|
11
42
|
end
|
data/lib/line/social/profile.rb
CHANGED
@@ -2,12 +2,24 @@ module Line
|
|
2
2
|
module Social
|
3
3
|
module Request
|
4
4
|
class Friendship < Base
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
API_URI = URI.parse("https://api.line.me/friendship/v1")
|
6
|
+
|
7
|
+
def get(access_token)
|
8
|
+
response = http_client.get do |request|
|
9
|
+
request.url "#{API_URI}/status"
|
10
|
+
request.headers["Authorization"] = "Bearer #{access_token}"
|
11
|
+
end
|
12
|
+
|
13
|
+
if response.body["error"]
|
14
|
+
raise Line::Social::Error.new(response.body["error_description"])
|
15
|
+
end
|
16
|
+
|
17
|
+
# Case of "{"message"=>"There is no login bot linked to this channel."}"
|
18
|
+
if response.body["message"]
|
19
|
+
raise Line::Social::Error.new(response.body["message"])
|
20
|
+
end
|
8
21
|
|
9
|
-
|
10
|
-
raise Line::Social::NotImplementedError
|
22
|
+
Line::Social::Friendship.new(response.body)
|
11
23
|
end
|
12
24
|
end
|
13
25
|
end
|
@@ -4,30 +4,72 @@ module Line
|
|
4
4
|
class Oauth < Base
|
5
5
|
API_URI = URI.parse("https://api.line.me/oauth2/v2.1")
|
6
6
|
|
7
|
-
def initialize(
|
8
|
-
@
|
7
|
+
def initialize(client_id:, client_secret:)
|
8
|
+
@client_id = client_id
|
9
|
+
@client_secret = client_secret
|
9
10
|
end
|
10
11
|
|
11
|
-
def issue
|
12
|
-
|
12
|
+
def issue(code:, redirect_uri:)
|
13
|
+
response = http_client.post do |request|
|
14
|
+
request.url "#{API_URI}/token"
|
15
|
+
request.headers['Content-Type'] = 'application/x-www-form-urlencoded'
|
16
|
+
request.body = URI.encode_www_form(
|
17
|
+
client_id: @client_id,
|
18
|
+
client_secret: @client_secret,
|
19
|
+
code: code,
|
20
|
+
grant_type: "authorization_code",
|
21
|
+
redirect_uri: redirect_uri,
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
if response.body["error"]
|
26
|
+
raise Line::Social::Error.new(response.body["error_description"])
|
27
|
+
end
|
28
|
+
|
29
|
+
Line::Social::Oauth.new(response.body.merge(client_id: @client_id, client_secret: @client_secret))
|
13
30
|
end
|
14
31
|
|
15
|
-
def verify
|
16
|
-
response =
|
32
|
+
def verify(access_token)
|
33
|
+
response = http_client.get("#{API_URI}/verify", access_token: access_token)
|
17
34
|
|
18
35
|
if response.body["error"]
|
19
36
|
raise Line::Social::Error.new(response.body["error_description"])
|
20
|
-
else
|
21
|
-
Line::Social::Oauth.new(response.body)
|
22
37
|
end
|
38
|
+
|
39
|
+
Line::Social::Oauth.new(response.body.merge(client_id: @client_id, client_secret: @client_secret))
|
23
40
|
end
|
24
41
|
|
25
|
-
def refresh
|
26
|
-
|
42
|
+
def refresh(refresh_token)
|
43
|
+
response = http_client.post do |request|
|
44
|
+
request.url "#{API_URI}/token"
|
45
|
+
request.headers['Content-Type'] = 'application/x-www-form-urlencoded'
|
46
|
+
request.body = URI.encode_www_form(
|
47
|
+
client_id: @client_id,
|
48
|
+
client_secret: @client_secret,
|
49
|
+
grant_type: "refresh_token",
|
50
|
+
refresh_token: refresh_token,
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
if response.body["error"]
|
55
|
+
raise Line::Social::Error.new(response.body["error_description"])
|
56
|
+
end
|
57
|
+
|
58
|
+
Line::Social::Oauth.new(response.body.merge(client_id: @client_id, client_secret: @client_secret))
|
27
59
|
end
|
28
60
|
|
29
|
-
def revoke
|
30
|
-
|
61
|
+
def revoke(access_token)
|
62
|
+
response = http_client.post do |request|
|
63
|
+
request.url "#{API_URI}/revoke"
|
64
|
+
request.headers['Content-Type'] = 'application/x-www-form-urlencoded'
|
65
|
+
request.body = URI.encode_www_form(
|
66
|
+
access_token: access_token,
|
67
|
+
client_id: @client_id,
|
68
|
+
client_secret: @client_secret
|
69
|
+
)
|
70
|
+
end
|
71
|
+
|
72
|
+
response.status == 200
|
31
73
|
end
|
32
74
|
end
|
33
75
|
end
|
@@ -4,21 +4,17 @@ module Line
|
|
4
4
|
class Profile < Base
|
5
5
|
API_URI = URI.parse("https://api.line.me/v2")
|
6
6
|
|
7
|
-
def
|
8
|
-
|
9
|
-
end
|
10
|
-
|
11
|
-
def get
|
12
|
-
response = request.get do |request|
|
7
|
+
def get(access_token)
|
8
|
+
response = http_client.get do |request|
|
13
9
|
request.url "#{API_URI}/profile"
|
14
|
-
request.headers["Authorization"] = "Bearer #{
|
10
|
+
request.headers["Authorization"] = "Bearer #{access_token}"
|
15
11
|
end
|
16
12
|
|
17
13
|
if response.body["error"]
|
18
14
|
raise Line::Social::Error.new(response.body["error_description"])
|
19
|
-
else
|
20
|
-
Line::Social::Profile.new(response.body)
|
21
15
|
end
|
16
|
+
|
17
|
+
Line::Social::Profile.new(response.body)
|
22
18
|
end
|
23
19
|
end
|
24
20
|
end
|
data/lib/line/social/version.rb
CHANGED
data/lib/line/social.rb
CHANGED
@@ -8,6 +8,7 @@ require "line/social/request/base"
|
|
8
8
|
require "line/social/request/oauth"
|
9
9
|
require "line/social/request/profile"
|
10
10
|
require "line/social/request/friendship"
|
11
|
+
require "line/social/friendship"
|
11
12
|
require "line/social/oauth"
|
12
13
|
require "line/social/profile"
|
13
14
|
require "line/social/error"
|
data/line-social.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["camelmasa"]
|
10
10
|
spec.email = ["camelmasa@gmail.com"]
|
11
11
|
|
12
|
-
spec.summary = %q{Ruby client for LINE
|
13
|
-
spec.description = %q{Ruby client for LINE
|
12
|
+
spec.summary = %q{Ruby client for LINE Social API}
|
13
|
+
spec.description = %q{Ruby client for LINE Social API}
|
14
14
|
spec.homepage = "https://github.com/camelmasa/line-social"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: line-social
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- camelmasa
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-04-
|
11
|
+
date: 2019-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -94,7 +94,7 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '3.0'
|
97
|
-
description: Ruby client for LINE
|
97
|
+
description: Ruby client for LINE Social API
|
98
98
|
email:
|
99
99
|
- camelmasa@gmail.com
|
100
100
|
executables: []
|
@@ -114,6 +114,7 @@ files:
|
|
114
114
|
- lib/line/social.rb
|
115
115
|
- lib/line/social/client.rb
|
116
116
|
- lib/line/social/error.rb
|
117
|
+
- lib/line/social/friendship.rb
|
117
118
|
- lib/line/social/oauth.rb
|
118
119
|
- lib/line/social/profile.rb
|
119
120
|
- lib/line/social/request/base.rb
|
@@ -144,5 +145,5 @@ requirements: []
|
|
144
145
|
rubygems_version: 3.0.3
|
145
146
|
signing_key:
|
146
147
|
specification_version: 4
|
147
|
-
summary: Ruby client for LINE
|
148
|
+
summary: Ruby client for LINE Social API
|
148
149
|
test_files: []
|