line-social 0.1.2 → 1.0.0

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: ad1f3541e668c583eb447ab3fdf3987f86bf224cbcd5cc4d1164eb505cbf86eb
4
- data.tar.gz: 36dcc8cb36d86f41afd09e223546e7ba5e60500013d1b7be68466b77abbec33d
3
+ metadata.gz: bddb24a7a0f87bbfb1c0da8cace65bc2fbeff831aeeed14302b36475d7b740ac
4
+ data.tar.gz: 97cc163c482394a8dfb20742dcf712c289637f50e9c4a3489f03cf699c9da485
5
5
  SHA512:
6
- metadata.gz: 27179ef7fa87232c710388e71db66006b3fb72f4fb9c5179a419bb186a8cb1c44838301d6afb19886d5519ad415238af66f14ba683fa6ab5bdd7ea1d35697549
7
- data.tar.gz: 0c66c13dbd87da9348f9f90e4cf04f20c61e6dd071783a26286f2c07159ef8554950a7121ae6a2fb5078fb25ebdb9672d2276ff5390820e1dd46b2cc32687a8f
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
@@ -11,7 +11,7 @@ GIT
11
11
  PATH
12
12
  remote: .
13
13
  specs:
14
- line-social (0.1.1)
14
+ line-social (1.0.0)
15
15
  faraday (~> 0.15)
16
16
  faraday_middleware (~> 0.13)
17
17
  virtus (~> 1.0)
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # Line::Social
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/line/social`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ [![Build Status](https://travis-ci.org/camelmasa/line-social.png)](https://travis-ci.org/camelmasa/line-social)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/c74659829afe420dd9e0/maintainability)](https://codeclimate.com/github/camelmasa/line-social/maintainability)
5
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/c74659829afe420dd9e0/test_coverage)](https://codeclimate.com/github/camelmasa/line-social/test_coverage)
4
6
 
5
- TODO: Delete this and the text above, and describe your gem
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
- TODO: Write usage instructions here
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
 
@@ -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(@access_token)
5
+ Request::Friendship.new
10
6
  end
11
7
 
12
- def oauth
13
- Request::Oauth.new(@access_token)
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(@access_token)
13
+ Request::Profile.new
18
14
  end
19
15
  end
20
16
  end
@@ -0,0 +1,9 @@
1
+ module Line
2
+ module Social
3
+ class Friendship
4
+ include Virtus.model(strict: true)
5
+
6
+ attribute :friendFlag, Boolean
7
+ end
8
+ end
9
+ end
@@ -3,9 +3,40 @@ module Line
3
3
  class Oauth
4
4
  include Virtus.model(strict: true)
5
5
 
6
- attribute :scope, String
7
- attribute :client_id, String
8
- attribute :expires_in, String
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
@@ -5,8 +5,8 @@ module Line
5
5
 
6
6
  attribute :userId, String
7
7
  attribute :displayName, String
8
- attribute :pictureUrl
9
- attribute :statusMessage
8
+ attribute :pictureUrl, String, required: false
9
+ attribute :statusMessage, String, required: false
10
10
  end
11
11
  end
12
12
  end
@@ -2,7 +2,7 @@ module Line
2
2
  module Social
3
3
  module Request
4
4
  class Base
5
- def request
5
+ def http_client
6
6
  Faraday.new do |connection|
7
7
  connection.response :json, content_type: /\bjson$/
8
8
  connection.adapter Faraday.default_adapter
@@ -2,12 +2,24 @@ module Line
2
2
  module Social
3
3
  module Request
4
4
  class Friendship < Base
5
- def initialize(access_token)
6
- @access_token = access_token
7
- end
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
- def get
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(access_token)
8
- @access_token = access_token
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
- raise Line::Social::NotImplementedError
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 = request.get("#{API_URI}/verify", access_token: @access_token)
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
- raise Line::Social::NotImplementedError
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
- raise Line::Social::NotImplementedError
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 initialize(access_token)
8
- @access_token = access_token
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 #{@access_token}"
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
@@ -1,5 +1,5 @@
1
1
  module Line
2
2
  module Social
3
- VERSION = "0.1.2"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
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 social API}
13
- spec.description = %q{Ruby client for LINE social API}
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.1.2
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-09 00:00:00.000000000 Z
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 social API
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 social API
148
+ summary: Ruby client for LINE Social API
148
149
  test_files: []