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.
@@ -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
@@ -13,7 +13,7 @@ module Croudia
13
13
  @attrs['id_str'] ||= id.to_s
14
14
  end
15
15
 
16
- # @param other [Croudia::Identity]
16
+ # @param [Croudia::Identity] other
17
17
  # @return [Boolean]
18
18
  def ==(other)
19
19
  super || self.class == other.class && id == other.id
@@ -0,0 +1,10 @@
1
+ require 'croudia/base'
2
+
3
+ module Croudia
4
+ class Place < Base
5
+ attr_reader(
6
+ :name,
7
+ :woeid
8
+ )
9
+ end
10
+ end
@@ -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,13 @@
1
+ require 'croudia/base'
2
+
3
+ module Croudia
4
+ class Trend < Base
5
+ attr_reader(
6
+ :name,
7
+ :promoted_content,
8
+ :query
9
+ )
10
+
11
+ alias to_s name
12
+ end
13
+ end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Croudia
2
- VERSION = '1.0.15'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -6,38 +6,22 @@ describe Croudia::API::Favorites do
6
6
  end
7
7
 
8
8
  describe '#favorites' do
9
- context 'when user is not specified' do
10
- before do
11
- stub_get('/favorites.json').to_return(
12
- body: fixture(:timeline),
13
- headers: { content_type: 'application/json; charset=utf-8' }
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
- context 'when user is specified' do
30
- before do
31
- stub_get('/favorites/wktk.json').to_return(
32
- body: fixture(:timeline),
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
- it 'requests the correct resource' do
38
- @client.favorites('wktk')
39
- expect(a_get('/favorites/wktk.json')).to have_been_made
40
- end
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
@@ -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