tinderb 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -2
- data/lib/tinderb.rb +1 -0
- data/lib/tinderb/client.rb +24 -4
- data/lib/tinderb/errors.rb +9 -0
- data/lib/tinderb/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 339612d7f34703736c385bb7b00931b335a0c908949fa8c511fa0f2321bbbe46
|
4
|
+
data.tar.gz: b2159cfdccb45155e47cb9b4f001a74f95c420988365f4c597133c171c46d374
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
27
|
+
client = Tinderb::Client.new(facebook_token: facebook_token)
|
29
28
|
client.authorize
|
30
29
|
|
31
30
|
# and more using apis...
|
data/lib/tinderb.rb
CHANGED
data/lib/tinderb/client.rb
CHANGED
@@ -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
|
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:
|
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
|
-
|
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
|
data/lib/tinderb/version.rb
CHANGED
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.
|
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
|