Class: Esa::Client

Inherits:
Object
  • Object
show all
Includes:
ApiMethods
Defined in:
lib/esa/client.rb

Constant Summary

Constants included from ApiMethods

ApiMethods::HTTP_REGEX

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ApiMethods

#add_comment_star, #add_post_star, #add_watch, #comment, #comment_stargazers, #comments, #create_comment, #create_post, #create_sharing, #delete_comment, #delete_comment_star, #delete_post, #delete_post_star, #delete_sharing, #delete_watch, #members, #post, #post_stargazers, #posts, #stats, #team, #teams, #update_comment, #update_post, #upload_attachment, #user, #watchers

Constructor Details

#initialize(access_token: nil, api_endpoint: nil, current_team: nil) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
# File 'lib/esa/client.rb', line 9

def initialize(access_token: nil, api_endpoint: nil, current_team: nil)
  @access_token = access_token
  @api_endpoint = api_endpoint
  @current_team = current_team
end

Instance Attribute Details

#current_teamObject

Returns the value of attribute current_team.



14
15
16
# File 'lib/esa/client.rb', line 14

def current_team
  @current_team
end

Instance Method Details

#current_team!Object



16
17
18
19
# File 'lib/esa/client.rb', line 16

def current_team!
  raise TeamNotSpecifiedError, "current_team is not specified" unless @current_team
  current_team
end

#esa_connectionObject



53
54
55
56
57
58
59
# File 'lib/esa/client.rb', line 53

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_connectionObject



61
62
63
64
65
66
67
68
# File 'lib/esa/client.rb', line 61

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



37
38
39
# File 'lib/esa/client.rb', line 37

def send_delete(path, params = nil, headers = nil)
  send_request(:delete, path, params, headers)
end

#send_get(path, params = nil, headers = nil) ⇒ Object



21
22
23
# File 'lib/esa/client.rb', line 21

def send_get(path, params = nil, headers = nil)
  send_request(:get, path, params, headers)
end

#send_patch(path, params = nil, headers = nil) ⇒ Object



33
34
35
# File 'lib/esa/client.rb', line 33

def send_patch(path, params = nil, headers = nil)
  send_request(:patch, path, params, headers)
end

#send_post(path, params = nil, headers = nil) ⇒ Object



25
26
27
# File 'lib/esa/client.rb', line 25

def send_post(path, params = nil, headers = nil)
  send_request(:post, path, params, headers)
end

#send_put(path, params = nil, headers = nil) ⇒ Object



29
30
31
# File 'lib/esa/client.rb', line 29

def send_put(path, params = nil, headers = nil)
  send_request(:put, path, params, headers)
end

#send_request(method, path, params = nil, headers = nil) ⇒ Object



41
42
43
# File 'lib/esa/client.rb', line 41

def send_request(method, path, params = nil, headers = nil)
  Esa::Response.new(esa_connection.send(method, path, params, headers))
end

#send_s3_request(method, path, params = nil, headers = nil) ⇒ Object



45
46
47
# File 'lib/esa/client.rb', line 45

def send_s3_request(method, path, params = nil, headers = nil)
  Esa::Response.new(s3_connection.send(method, path, params, headers))
end

#send_simple_request(method, path, params = nil, headers = nil) ⇒ Object



49
50
51
# File 'lib/esa/client.rb', line 49

def send_simple_request(method, path, params = nil, headers = nil)
  Esa::Response.new(simple_connection.send(method, path, params, headers))
end

#simple_connectionObject



70
71
72
73
74
# File 'lib/esa/client.rb', line 70

def simple_connection
  @simple_connection ||= Faraday.new do |c|
    c.adapter Faraday.default_adapter
  end
end