tinderb 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 25401d68a4b799631303c4e546386e383ccf04c56395008f4183e30bae585d01
4
- data.tar.gz: 8584dd55afb8630981f95611ece884abb59acece15e210b21b4c03ea74e5c719
3
+ metadata.gz: 339612d7f34703736c385bb7b00931b335a0c908949fa8c511fa0f2321bbbe46
4
+ data.tar.gz: b2159cfdccb45155e47cb9b4f001a74f95c420988365f4c597133c171c46d374
5
5
  SHA512:
6
- metadata.gz: 558764734cdbb0d0885dfe7ea0044534e613483927033581e142d5863bb9b8b6050533e25fdcfe307d4f26bcc3487fff2b7277df92a02b3add249e552c40ec7f
7
- data.tar.gz: 7344527a0f86be7d2461c2c63f6456aa6a566f7f4398eeba2294c3826c173c6a74d1d022e45bc8cf2a625c3548da1de07c212d0087b90fb8403e743d62c81829
6
+ metadata.gz: c08fc561aa77b328c48a38e25440e98f4014dacef1e13a1502617fd74037c5379fdfe17094b277b2dd214bd3069dcb1aa86c9607af8ffb6ee2f66bebb6e95385
7
+ data.tar.gz: 93e11afc5b6e4f4fda4b8b486c94dbbb8486af002db29661fe60623604a25bdcb5d0d4c6d070434bcd870d9596c042176b8b4bd67c19814f815fcf7db397a189
data/README.md CHANGED
@@ -3,7 +3,6 @@
3
3
 
4
4
  # Tinderb
5
5
 
6
-
7
6
  ## Installation
8
7
 
9
8
  Add this line to your application's Gemfile:
@@ -25,7 +24,7 @@ Or install it yourself as:
25
24
  ```ruby
26
25
  require 'tinderb'
27
26
 
28
- client = Tinderb.client.new(facebook_token: facebook_token, facebook_id: facebook_id)
27
+ client = Tinderb::Client.new(facebook_token: facebook_token)
29
28
  client.authorize
30
29
 
31
30
  # and more using apis...
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'tinderb/version'
4
+ require 'tinderb/errors'
4
5
  require 'tinderb/client'
5
6
 
6
7
  module Tinderb
@@ -2,28 +2,48 @@
2
2
 
3
3
  require 'tinderb'
4
4
  require 'tinderb/request'
5
-
5
+ require 'tinderb/errors'
6
6
  module Tinderb
7
7
  class Client
8
8
  include Request
9
9
 
10
- def initialize(facebook_token: nil, facebook_id: nil)
10
+ def initialize(facebook_token:, facebook_id: nil)
11
11
  @oauth_params = params(facebook_token, facebook_id)
12
12
  end
13
13
 
14
14
  def params(facebook_token, facebook_id)
15
15
  {
16
- facebook_token: ENV.fetch('FACEBOOK_TOKEN', facebook_token),
16
+ facebook_token: facebook_token,
17
17
  facebook_id: ENV.fetch('FACEBOOK_ID', facebook_id)
18
18
  }
19
19
  end
20
20
 
21
21
  def authorize
22
22
  res = post(OAUTH_PATH, @oauth_params)
23
- raise "error occurred. body: #{res.body}" unless res.status == 200
23
+ classify_error(res)
24
24
  @token = res.body['token']
25
25
 
26
26
  res
27
27
  end
28
+
29
+ private
30
+
31
+ def classify_error(res)
32
+ error = case res.status
33
+ when 200
34
+ when 301
35
+ Tinderb::Errors::MovedPermanently
36
+ when 400
37
+ Tinderb::Errors::BadRequest
38
+ when 401
39
+ Tinderb::Errors::Unauthorized
40
+ when 404
41
+ Tinderb::Errors::NotFound
42
+ when 500
43
+ Tinderb::Errors::InternalServerError
44
+ end
45
+ body = res.body
46
+ raise error.new("#{body['error']}, error_no: #{body['error_no']}") unless res.status == 200
47
+ end
28
48
  end
29
49
  end
@@ -0,0 +1,9 @@
1
+ module Tinderb
2
+ class Errors
3
+ class InternalServerError < RuntimeError; end # 500
4
+ class NotFound < StandardError; end #404
5
+ class Unauthorized < StandardError; end # 401
6
+ class BadRequest < StandardError; end # 400
7
+ class MovedPermanently < StandardError; end # 301
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tinderb
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tinderb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryota Ikezawa
@@ -185,6 +185,7 @@ files:
185
185
  - bin/setup
186
186
  - lib/tinderb.rb
187
187
  - lib/tinderb/client.rb
188
+ - lib/tinderb/errors.rb
188
189
  - lib/tinderb/request.rb
189
190
  - lib/tinderb/version.rb
190
191
  - tinderb.gemspec