croudia 1.0.15 → 1.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 +13 -5
- data/.gitignore +1 -0
- data/README.md +4 -1
- data/lib/croudia/api/account.rb +16 -5
- data/lib/croudia/api/favorites.rb +16 -15
- data/lib/croudia/api/friendships.rb +84 -22
- data/lib/croudia/api/oauth.rb +20 -4
- data/lib/croudia/api/search.rb +34 -5
- data/lib/croudia/api/secret_mails.rb +29 -11
- data/lib/croudia/api/statuses.rb +56 -19
- data/lib/croudia/api/timelines.rb +43 -5
- data/lib/croudia/api/trends.rb +20 -0
- data/lib/croudia/api/users.rb +16 -4
- data/lib/croudia/base.rb +71 -71
- data/lib/croudia/client.rb +4 -3
- data/lib/croudia/creatable.rb +1 -0
- data/lib/croudia/default.rb +70 -70
- data/lib/croudia/error.rb +49 -49
- data/lib/croudia/identity.rb +1 -1
- data/lib/croudia/place.rb +10 -0
- data/lib/croudia/request/raise_error.rb +19 -19
- data/lib/croudia/response/raise_error.rb +38 -38
- data/lib/croudia/trend.rb +13 -0
- data/lib/croudia/trend_results.rb +24 -0
- data/lib/croudia/version.rb +1 -1
- data/spec/croudia/api/favorites_spec.rb +13 -29
- data/spec/croudia/api/trends_spec.rb +29 -0
- data/spec/croudia/error_spec.rb +46 -46
- data/spec/fixtures/trends.json +20 -0
- metadata +13 -6
- data/lib/croudia/ext/openssl.rb +0 -19
data/lib/croudia/error.rb
CHANGED
@@ -1,49 +1,49 @@
|
|
1
|
-
module Croudia
|
2
|
-
class Error < StandardError
|
3
|
-
|
4
|
-
# Error connecting to server
|
5
|
-
class NetworkError < Error
|
6
|
-
attr_reader :wrapped_exception
|
7
|
-
|
8
|
-
def initialize(e)
|
9
|
-
@wrapped_exception = e
|
10
|
-
super(e.respond_to?(:message) ? e.message : e.to_s)
|
11
|
-
end
|
12
|
-
|
13
|
-
def backtrace
|
14
|
-
if @wrapped_exception.respond_to?(:backtrace)
|
15
|
-
@wrapped_exception.backtrace
|
16
|
-
else
|
17
|
-
super
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
class Timeout < NetworkError; end
|
23
|
-
|
24
|
-
# Error connected to server
|
25
|
-
class ConnectionError < Error
|
26
|
-
attr_reader :code, :env, :error
|
27
|
-
|
28
|
-
def initialize(env)
|
29
|
-
@code = env[:status]
|
30
|
-
@error = env[:body]['error'] rescue nil
|
31
|
-
@env = env
|
32
|
-
super(@error)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
# 4xx: Client Errors
|
37
|
-
class ClientError < ConnectionError; end
|
38
|
-
class BadRequest < ClientError; end
|
39
|
-
class Unauthorized < ClientError; end
|
40
|
-
class Forbidden < ClientError; end
|
41
|
-
class NotFound < ClientError; end
|
42
|
-
|
43
|
-
# 5xx: Server Errors
|
44
|
-
class ServerError < ConnectionError; end
|
45
|
-
class InternalServerError < ServerError; end
|
46
|
-
class BadGateway < ServerError; end
|
47
|
-
class Unavailable < ServerError; end
|
48
|
-
end
|
49
|
-
end
|
1
|
+
module Croudia
|
2
|
+
class Error < StandardError
|
3
|
+
|
4
|
+
# Error connecting to server
|
5
|
+
class NetworkError < Error
|
6
|
+
attr_reader :wrapped_exception
|
7
|
+
|
8
|
+
def initialize(e)
|
9
|
+
@wrapped_exception = e
|
10
|
+
super(e.respond_to?(:message) ? e.message : e.to_s)
|
11
|
+
end
|
12
|
+
|
13
|
+
def backtrace
|
14
|
+
if @wrapped_exception.respond_to?(:backtrace)
|
15
|
+
@wrapped_exception.backtrace
|
16
|
+
else
|
17
|
+
super
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Timeout < NetworkError; end
|
23
|
+
|
24
|
+
# Error connected to server
|
25
|
+
class ConnectionError < Error
|
26
|
+
attr_reader :code, :env, :error
|
27
|
+
|
28
|
+
def initialize(env)
|
29
|
+
@code = env[:status]
|
30
|
+
@error = env[:body]['error'] rescue nil
|
31
|
+
@env = env
|
32
|
+
super(@error)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# 4xx: Client Errors
|
37
|
+
class ClientError < ConnectionError; end
|
38
|
+
class BadRequest < ClientError; end
|
39
|
+
class Unauthorized < ClientError; end
|
40
|
+
class Forbidden < ClientError; end
|
41
|
+
class NotFound < ClientError; end
|
42
|
+
|
43
|
+
# 5xx: Server Errors
|
44
|
+
class ServerError < ConnectionError; end
|
45
|
+
class InternalServerError < ServerError; end
|
46
|
+
class BadGateway < ServerError; end
|
47
|
+
class Unavailable < ServerError; end
|
48
|
+
end
|
49
|
+
end
|
data/lib/croudia/identity.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
|
-
require 'croudia/error'
|
2
|
-
require 'faraday'
|
3
|
-
|
4
|
-
module Croudia
|
5
|
-
module Request
|
6
|
-
class RaiseError < Faraday::Middleware
|
7
|
-
def call(env)
|
8
|
-
@app.call(env)
|
9
|
-
rescue Faraday::Error::TimeoutError => e
|
10
|
-
raise Croudia::Error::Timeout.new(e)
|
11
|
-
rescue Faraday::Error::ConnectionFailed => e
|
12
|
-
raise Croudia::Error::NetworkError.new(e)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
Faraday.register_middleware :request,
|
19
|
-
raise_error: lambda { Croudia::Request::RaiseError }
|
1
|
+
require 'croudia/error'
|
2
|
+
require 'faraday'
|
3
|
+
|
4
|
+
module Croudia
|
5
|
+
module Request
|
6
|
+
class RaiseError < Faraday::Middleware
|
7
|
+
def call(env)
|
8
|
+
@app.call(env)
|
9
|
+
rescue Faraday::Error::TimeoutError => e
|
10
|
+
raise Croudia::Error::Timeout.new(e)
|
11
|
+
rescue Faraday::Error::ConnectionFailed => e
|
12
|
+
raise Croudia::Error::NetworkError.new(e)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
Faraday.register_middleware :request,
|
19
|
+
raise_error: lambda { Croudia::Request::RaiseError }
|
@@ -1,38 +1,38 @@
|
|
1
|
-
require 'croudia/error'
|
2
|
-
require 'faraday'
|
3
|
-
|
4
|
-
module Croudia
|
5
|
-
module Response
|
6
|
-
class RaiseError < Faraday::Response::Middleware
|
7
|
-
def on_complete(env)
|
8
|
-
error_class = case env[:status]
|
9
|
-
when 400
|
10
|
-
Croudia::Error::BadRequest
|
11
|
-
when 401
|
12
|
-
Croudia::Error::Unauthorized
|
13
|
-
when 403
|
14
|
-
Croudia::Error::Forbidden
|
15
|
-
when 404
|
16
|
-
Croudia::Error::NotFound
|
17
|
-
when 400 .. 499
|
18
|
-
Croudia::Error::ClientError
|
19
|
-
when 500
|
20
|
-
Croudia::Error::InternalServerError
|
21
|
-
when 502
|
22
|
-
Croudia::Error::BadGateway
|
23
|
-
when 503
|
24
|
-
Croudia::Error::Unavailable
|
25
|
-
when 500 .. 599
|
26
|
-
Croudia::Error::ServerError
|
27
|
-
else
|
28
|
-
return
|
29
|
-
end
|
30
|
-
|
31
|
-
raise error_class.new(env)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
Faraday.register_middleware :response,
|
38
|
-
raise_error: lambda { Croudia::Response::RaiseError }
|
1
|
+
require 'croudia/error'
|
2
|
+
require 'faraday'
|
3
|
+
|
4
|
+
module Croudia
|
5
|
+
module Response
|
6
|
+
class RaiseError < Faraday::Response::Middleware
|
7
|
+
def on_complete(env)
|
8
|
+
error_class = case env[:status]
|
9
|
+
when 400
|
10
|
+
Croudia::Error::BadRequest
|
11
|
+
when 401
|
12
|
+
Croudia::Error::Unauthorized
|
13
|
+
when 403
|
14
|
+
Croudia::Error::Forbidden
|
15
|
+
when 404
|
16
|
+
Croudia::Error::NotFound
|
17
|
+
when 400 .. 499
|
18
|
+
Croudia::Error::ClientError
|
19
|
+
when 500
|
20
|
+
Croudia::Error::InternalServerError
|
21
|
+
when 502
|
22
|
+
Croudia::Error::BadGateway
|
23
|
+
when 503
|
24
|
+
Croudia::Error::Unavailable
|
25
|
+
when 500 .. 599
|
26
|
+
Croudia::Error::ServerError
|
27
|
+
else
|
28
|
+
return
|
29
|
+
end
|
30
|
+
|
31
|
+
raise error_class.new(env)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
Faraday.register_middleware :response,
|
38
|
+
raise_error: lambda { Croudia::Response::RaiseError }
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'croudia/base'
|
2
|
+
require 'croudia/creatable'
|
3
|
+
require 'croudia/place'
|
4
|
+
require 'croudia/trend'
|
5
|
+
require 'time'
|
6
|
+
|
7
|
+
module Croudia
|
8
|
+
class TrendResults < Base
|
9
|
+
include Croudia::Creatable
|
10
|
+
|
11
|
+
attr_object_reader(
|
12
|
+
locations: Croudia::Place,
|
13
|
+
trends: Array(Croudia::Trend)
|
14
|
+
)
|
15
|
+
|
16
|
+
alias location locations
|
17
|
+
alias to_a trends
|
18
|
+
|
19
|
+
# @return [Time]
|
20
|
+
def as_of
|
21
|
+
@as_of ||= Time.parse(@attrs['as_of'])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/croudia/version.rb
CHANGED
@@ -6,38 +6,22 @@ describe Croudia::API::Favorites do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
describe '#favorites' do
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
)
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'requests the correct resource' do
|
18
|
-
@client.favorites
|
19
|
-
expect(a_get('/favorites.json')).to have_been_made
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'returns Array of Croudia::Status' do
|
23
|
-
subject = @client.favorites
|
24
|
-
expect(subject).to be_an Array
|
25
|
-
subject.each { |s| expect(s).to be_a Croudia::Status }
|
26
|
-
end
|
9
|
+
before do
|
10
|
+
stub_get('/favorites.json').to_return(
|
11
|
+
body: fixture(:timeline),
|
12
|
+
headers: { content_type: 'application/json; charset=utf-8' }
|
13
|
+
)
|
27
14
|
end
|
28
15
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
headers: { content_type: 'application/json; charset=utf-8' }
|
34
|
-
)
|
35
|
-
end
|
16
|
+
it 'requests the correct resource' do
|
17
|
+
@client.favorites
|
18
|
+
expect(a_get('/favorites.json')).to have_been_made
|
19
|
+
end
|
36
20
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
21
|
+
it 'returns Array of Croudia::Status' do
|
22
|
+
subject = @client.favorites
|
23
|
+
expect(subject).to be_an Array
|
24
|
+
subject.each { |s| expect(s).to be_a Croudia::Status }
|
41
25
|
end
|
42
26
|
end
|
43
27
|
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Croudia::API::Trends do
|
4
|
+
before do
|
5
|
+
@client = Croudia::Client.new
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '#trends' do
|
9
|
+
before do
|
10
|
+
stub_get('/trends/place.json').with(
|
11
|
+
query: { id: '1' }
|
12
|
+
).to_return(
|
13
|
+
body: fixture(:trends),
|
14
|
+
headers: { content_type: 'application/json; chrset=utf-8' }
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'requests the correct resource' do
|
19
|
+
@client.trends
|
20
|
+
expect(a_get('/trends/place.json').with(
|
21
|
+
query: { id: '1' }
|
22
|
+
)).to have_been_made
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'returns TrendResults object' do
|
26
|
+
expect(@client.trends).to be_a Croudia::TrendResults
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/spec/croudia/error_spec.rb
CHANGED
@@ -1,46 +1,46 @@
|
|
1
|
-
require 'faraday'
|
2
|
-
require 'helper'
|
3
|
-
|
4
|
-
describe Croudia::Error do
|
5
|
-
before do
|
6
|
-
@client = Croudia::Client.new
|
7
|
-
end
|
8
|
-
|
9
|
-
context 'connection error' do
|
10
|
-
before do
|
11
|
-
stub_get('/account/verify_credentials.json').to_raise Faraday::Error::ConnectionFailed
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'raises Croudia::Error::NetworkError' do
|
15
|
-
expect { @client.verify_credentials }.to raise_error Croudia::Error::NetworkError
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
context 'client error' do
|
20
|
-
before do
|
21
|
-
stub_get('/account/verify_credentials.json').to_return(
|
22
|
-
status: 401,
|
23
|
-
body: fixture(:error),
|
24
|
-
headers: { content_type: 'application/json; charset=utf-8' }
|
25
|
-
)
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'raises Croudia::Error::ClientError' do
|
29
|
-
expect { @client.verify_credentials }.to raise_error Croudia::Error::ClientError
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context 'server error' do
|
34
|
-
before do
|
35
|
-
stub_get('/account/verify_credentials.json').to_return(
|
36
|
-
status: 502,
|
37
|
-
body: fixture(:error),
|
38
|
-
headers: { content_type: 'application/json; charset=utf-8' }
|
39
|
-
)
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'raises Croudia::Error::ServerError' do
|
43
|
-
expect { @client.verify_credentials }.to raise_error Croudia::Error::ServerError
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
1
|
+
require 'faraday'
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
describe Croudia::Error do
|
5
|
+
before do
|
6
|
+
@client = Croudia::Client.new
|
7
|
+
end
|
8
|
+
|
9
|
+
context 'connection error' do
|
10
|
+
before do
|
11
|
+
stub_get('/account/verify_credentials.json').to_raise Faraday::Error::ConnectionFailed
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'raises Croudia::Error::NetworkError' do
|
15
|
+
expect { @client.verify_credentials }.to raise_error Croudia::Error::NetworkError
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'client error' do
|
20
|
+
before do
|
21
|
+
stub_get('/account/verify_credentials.json').to_return(
|
22
|
+
status: 401,
|
23
|
+
body: fixture(:error),
|
24
|
+
headers: { content_type: 'application/json; charset=utf-8' }
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'raises Croudia::Error::ClientError' do
|
29
|
+
expect { @client.verify_credentials }.to raise_error Croudia::Error::ClientError
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'server error' do
|
34
|
+
before do
|
35
|
+
stub_get('/account/verify_credentials.json').to_return(
|
36
|
+
status: 502,
|
37
|
+
body: fixture(:error),
|
38
|
+
headers: { content_type: 'application/json; charset=utf-8' }
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'raises Croudia::Error::ServerError' do
|
43
|
+
expect { @client.verify_credentials }.to raise_error Croudia::Error::ServerError
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|