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, faraday_middlewares: []) ⇒ 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, #compare_revisions, #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, #revision, #revisions, #send_invitation, #signed_url, #signed_urls, #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, faraday_middlewares: []) ⇒ Client
Returns a new instance of Client.
11
12
13
14
15
16
17
18
|
# 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, faraday_middlewares: [])
@access_token = access_token
@api_endpoint = api_endpoint
@current_team = current_team
=
@retry_on_rate_limit_exceeded = retry_on_rate_limit_exceeded
@faraday_middlewares = faraday_middlewares
end
|
Instance Attribute Details
#current_team ⇒ Object
Returns the value of attribute current_team.
19
20
21
|
# File 'lib/esa/client.rb', line 19
def current_team
@current_team
end
|
Returns the value of attribute default_headers.
19
20
21
|
# File 'lib/esa/client.rb', line 19
def
end
|
#faraday_middlewares ⇒ Object
Returns the value of attribute faraday_middlewares.
19
20
21
|
# File 'lib/esa/client.rb', line 19
def faraday_middlewares
@faraday_middlewares
end
|
#retry_on_rate_limit_exceeded ⇒ Object
Returns the value of attribute retry_on_rate_limit_exceeded.
19
20
21
|
# File 'lib/esa/client.rb', line 19
def retry_on_rate_limit_exceeded
@retry_on_rate_limit_exceeded
end
|
Instance Method Details
#current_team! ⇒ Object
21
22
23
24
|
# File 'lib/esa/client.rb', line 21
def current_team!
raise TeamNotSpecifiedError, "current_team is not specified" unless @current_team
current_team
end
|
#esa_connection ⇒ Object
65
66
67
68
69
70
71
72
|
# File 'lib/esa/client.rb', line 65
def esa_connection
@esa_connection ||= Faraday.new(faraday_options) do |c|
faraday_middlewares.each { |faraday_middleware| c.use faraday_middleware }
c.request :json
c.response :json
c.adapter Faraday.default_adapter
end
end
|
#s3_connection ⇒ Object
74
75
76
77
78
79
80
81
82
|
# File 'lib/esa/client.rb', line 74
def s3_connection
@s3_connection ||= Faraday.new do |c|
faraday_middlewares.each { |faraday_middleware| c.use faraday_middleware }
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
42
43
44
|
# File 'lib/esa/client.rb', line 42
def send_delete(path, params = nil, = nil)
send_request(:delete, path, params, )
end
|
#send_get(path, params = nil, headers = nil) ⇒ Object
26
27
28
|
# File 'lib/esa/client.rb', line 26
def send_get(path, params = nil, = nil)
send_request(:get, path, params, )
end
|
#send_patch(path, params = nil, headers = nil) ⇒ Object
38
39
40
|
# File 'lib/esa/client.rb', line 38
def send_patch(path, params = nil, = nil)
send_request(:patch, path, params, )
end
|
#send_post(path, params = nil, headers = nil) ⇒ Object
30
31
32
|
# File 'lib/esa/client.rb', line 30
def send_post(path, params = nil, = nil)
send_request(:post, path, params, )
end
|
#send_put(path, params = nil, headers = nil) ⇒ Object
34
35
36
|
# File 'lib/esa/client.rb', line 34
def send_put(path, params = nil, = nil)
send_request(:put, path, params, )
end
|
#send_request(method, path, params = nil, headers = nil) ⇒ Object
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/esa/client.rb', line 46
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
57
58
59
|
# File 'lib/esa/client.rb', line 57
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
61
62
63
|
# File 'lib/esa/client.rb', line 61
def send_simple_request(method, path, params = nil, = nil)
Esa::Response.new(simple_connection.send(method, path, params, ))
end
|
#simple_connection ⇒ Object
84
85
86
87
88
89
|
# File 'lib/esa/client.rb', line 84
def simple_connection
@simple_connection ||= Faraday.new do |c|
faraday_middlewares.each { |faraday_middleware| c.use faraday_middleware }
c.adapter Faraday.default_adapter
end
end
|