Class: Esa::Client
Defined Under Namespace
Classes: TooManyRequestError
Constant Summary
Constants included
from ApiMethods
ApiMethods::HTTP_REGEX
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#current_team! ⇒ Object
-
#esa_connection ⇒ Object
-
#initialize(access_token: nil, api_endpoint: nil, current_team: nil, default_headers: {}, retry_on_rate_limit_exceeded: true) ⇒ Client
constructor
A new instance of Client.
-
#s3_connection ⇒ Object
-
#send_delete(path, params = nil, headers = nil) ⇒ Object
-
#send_get(path, params = nil, headers = nil) ⇒ Object
-
#send_patch(path, params = nil, headers = nil) ⇒ Object
-
#send_post(path, params = nil, headers = nil) ⇒ Object
-
#send_put(path, params = nil, headers = nil) ⇒ Object
-
#send_request(method, path, params = nil, headers = nil) ⇒ Object
-
#send_s3_request(method, path, params = nil, headers = nil) ⇒ Object
-
#send_simple_request(method, path, params = nil, headers = nil) ⇒ Object
-
#simple_connection ⇒ Object
Methods included from ApiMethods
#add_comment_star, #add_post_star, #add_watch, #append_post, #batch_move_category, #cancel_invitation, #categories, #comment, #comment_stargazers, #comments, #create_comment, #create_emoji, #create_post, #create_sharing, #delete_comment, #delete_comment_star, #delete_emoji, #delete_member, #delete_post, #delete_post_star, #delete_sharing, #delete_watch, #emojis, #invitation, #member, #members, #pending_invitations, #post, #post_stargazers, #posts, #regenerate_invitation, #send_invitation, #signed_url, #stats, #tags, #team, #teams, #update_comment, #update_post, #upload_attachment, #user, #watchers
Constructor Details
#initialize(access_token: nil, api_endpoint: nil, current_team: nil, default_headers: {}, retry_on_rate_limit_exceeded: true) ⇒ Client
Returns a new instance of Client.
11
12
13
14
15
16
17
|
# File 'lib/esa/client.rb', line 11
def initialize(access_token: nil, api_endpoint: nil, current_team: nil, default_headers: {}, retry_on_rate_limit_exceeded: true)
@access_token = access_token
@api_endpoint = api_endpoint
@current_team = current_team
@default_headers =
@retry_on_rate_limit_exceeded = retry_on_rate_limit_exceeded
end
|
Instance Attribute Details
#current_team ⇒ Object
Returns the value of attribute current_team.
18
19
20
|
# File 'lib/esa/client.rb', line 18
def current_team
@current_team
end
|
Returns the value of attribute default_headers.
18
19
20
|
# File 'lib/esa/client.rb', line 18
def
@default_headers
end
|
#retry_on_rate_limit_exceeded ⇒ Object
Returns the value of attribute retry_on_rate_limit_exceeded.
18
19
20
|
# File 'lib/esa/client.rb', line 18
def retry_on_rate_limit_exceeded
@retry_on_rate_limit_exceeded
end
|
Instance Method Details
#current_team! ⇒ Object
20
21
22
23
|
# File 'lib/esa/client.rb', line 20
def current_team!
raise TeamNotSpecifiedError, "current_team is not specified" unless @current_team
current_team
end
|
#esa_connection ⇒ Object
64
65
66
67
68
69
70
|
# File 'lib/esa/client.rb', line 64
def esa_connection
@esa_connection ||= Faraday.new(faraday_options) do |c|
c.request :json
c.response :json
c.adapter Faraday.default_adapter
end
end
|
#s3_connection ⇒ Object
72
73
74
75
76
77
78
79
|
# File 'lib/esa/client.rb', line 72
def s3_connection
@s3_connection ||= Faraday.new do |c|
c.request :multipart
c.request :url_encoded
c.response :xml
c.adapter Faraday.default_adapter
end
end
|
#send_delete(path, params = nil, headers = nil) ⇒ Object
41
42
43
|
# File 'lib/esa/client.rb', line 41
def send_delete(path, params = nil, = nil)
send_request(:delete, path, params, )
end
|
#send_get(path, params = nil, headers = nil) ⇒ Object
25
26
27
|
# File 'lib/esa/client.rb', line 25
def send_get(path, params = nil, = nil)
send_request(:get, path, params, )
end
|
#send_patch(path, params = nil, headers = nil) ⇒ Object
37
38
39
|
# File 'lib/esa/client.rb', line 37
def send_patch(path, params = nil, = nil)
send_request(:patch, path, params, )
end
|
#send_post(path, params = nil, headers = nil) ⇒ Object
29
30
31
|
# File 'lib/esa/client.rb', line 29
def send_post(path, params = nil, = nil)
send_request(:post, path, params, )
end
|
#send_put(path, params = nil, headers = nil) ⇒ Object
33
34
35
|
# File 'lib/esa/client.rb', line 33
def send_put(path, params = nil, = nil)
send_request(:put, path, params, )
end
|
#send_request(method, path, params = nil, headers = nil) ⇒ Object
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/esa/client.rb', line 45
def send_request(method, path, params = nil, = nil)
response = esa_connection.send(method, path, params, )
raise TooManyRequestError if retry_on_rate_limit_exceeded && response.status == 429 Esa::Response.new(response)
rescue TooManyRequestError
wait_sec = response.['retry-after'].to_i + 5
puts "Rate limit exceeded: will retry after #{wait_sec} seconds."
wait_for(wait_sec)
retry
end
|
#send_s3_request(method, path, params = nil, headers = nil) ⇒ Object
56
57
58
|
# File 'lib/esa/client.rb', line 56
def send_s3_request(method, path, params = nil, = nil)
Esa::Response.new(s3_connection.send(method, path, params, ))
end
|
#send_simple_request(method, path, params = nil, headers = nil) ⇒ Object
60
61
62
|
# File 'lib/esa/client.rb', line 60
def send_simple_request(method, path, params = nil, = nil)
Esa::Response.new(simple_connection.send(method, path, params, ))
end
|
#simple_connection ⇒ Object
81
82
83
84
85
|
# File 'lib/esa/client.rb', line 81
def simple_connection
@simple_connection ||= Faraday.new do |c|
c.adapter Faraday.default_adapter
end
end
|