Class: Amocrm::Client

Inherits:
Internal::Transport::BaseClient show all
Defined in:
lib/amocrm/client.rb

Constant Summary collapse

DEFAULT_MAX_RETRIES =

Default max number of retries to attempt after a failed retryable request.

2
DEFAULT_TIMEOUT_IN_SECONDS =

Default per-request timeout.

60.0
DEFAULT_INITIAL_RETRY_DELAY =

Default initial retry delay in seconds. Overall delay is calculated using exponential backoff + jitter.

0.5
DEFAULT_MAX_RETRY_DELAY =

Default max retry delay in seconds.

8.0

Constants inherited from Internal::Transport::BaseClient

Internal::Transport::BaseClient::MAX_REDIRECTS, Internal::Transport::BaseClient::PLATFORM_HEADERS

Instance Attribute Summary collapse

Attributes inherited from Internal::Transport::BaseClient

#base_url, #headers, #idempotency_header, #initial_retry_delay, #max_retries, #max_retry_delay, #requester, #timeout

Instance Method Summary collapse

Methods inherited from Internal::Transport::BaseClient

follow_redirect, #inspect, reap_connection!, #request, #send_request, should_retry?, validate!

Methods included from Internal::Util::SorbetRuntimeSupport

#const_missing, #define_sorbet_constant!, #sorbet_constant_defined?, #to_sorbet_type, to_sorbet_type

Constructor Details

#initialize(token: ENV["AMOCRM_AUTH_TOKEN"], subdomain: ENV["AMOCRM_SUBDOMAIN"], base_url: ENV["AMOCRM_BASE_URL"], max_retries: self.class::DEFAULT_MAX_RETRIES, timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS, initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY, max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY) ⇒ Client

Creates and returns a new client for interacting with the API.

‘“api.example.com/v2/”`. Defaults to `ENV`

Parameters:

  • token (String, nil) (defaults to: ENV["AMOCRM_AUTH_TOKEN"])

    Defaults to ‘ENV`

  • subdomain (String, nil) (defaults to: ENV["AMOCRM_SUBDOMAIN"])

    Defaults to ‘ENV`

  • base_url (String, nil) (defaults to: ENV["AMOCRM_BASE_URL"])

    Override the default base URL for the API, e.g.,

  • max_retries (Integer) (defaults to: self.class::DEFAULT_MAX_RETRIES)

    Max number of retries to attempt after a failed retryable request.

  • timeout (Float) (defaults to: self.class::DEFAULT_TIMEOUT_IN_SECONDS)
  • initial_retry_delay (Float) (defaults to: self.class::DEFAULT_INITIAL_RETRY_DELAY)
  • max_retry_delay (Float) (defaults to: self.class::DEFAULT_MAX_RETRY_DELAY)


157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/amocrm/client.rb', line 157

def initialize(
  token: ENV["AMOCRM_AUTH_TOKEN"],
  subdomain: ENV["AMOCRM_SUBDOMAIN"],
  base_url: ENV["AMOCRM_BASE_URL"],
  max_retries: self.class::DEFAULT_MAX_RETRIES,
  timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS,
  initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY,
  max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY
)
  base_url ||= "https://#{subdomain}.amocrm.ru"

  if token.nil?
    raise ArgumentError.new("token is required, and can be set via environ: \"AMOCRM_AUTH_TOKEN\"")
  end
  if subdomain.nil?
    raise ArgumentError.new("subdomain is required, and can be set via environ: \"AMOCRM_SUBDOMAIN\"")
  end

  @token = token.to_s
  @subdomain = subdomain.to_s

  super(
    base_url: base_url,
    timeout: timeout,
    max_retries: max_retries,
    initial_retry_delay: initial_retry_delay,
    max_retry_delay: max_retry_delay
  )

  @account = Amocrm::Resources::Account.new(client: self)
  @calls = Amocrm::Resources::Calls.new(client: self)
  @catalog_elements = Amocrm::Resources::CatalogElements.new(client: self)
  @catalogs = Amocrm::Resources::Catalogs.new(client: self)
  @companies = Amocrm::Resources::Companies.new(client: self)
  @contact_chats = Amocrm::Resources::ContactChats.new(client: self)
  @contacts = Amocrm::Resources::Contacts.new(client: self)
  @custom_field_groups = Amocrm::Resources::CustomFieldGroups.new(client: self)
  @custom_fields = Amocrm::Resources::CustomFields.new(client: self)
  @customer_bonus_points = Amocrm::Resources::CustomerBonusPoints.new(client: self)
  @customer_segments = Amocrm::Resources::CustomerSegments.new(client: self)
  @customer_statuses = Amocrm::Resources::CustomerStatuses.new(client: self)
  @customer_transactions = Amocrm::Resources::CustomerTransactions.new(client: self)
  @customers = Amocrm::Resources::Customers.new(client: self)
  @customers_mode = Amocrm::Resources::CustomersMode.new(client: self)
  @entity_followers = Amocrm::Resources::EntityFollowers.new(client: self)
  @entity_links = Amocrm::Resources::EntityLinks.new(client: self)
  @entity_notes = Amocrm::Resources::EntityNotes.new(client: self)
  @entity_notes_by_parent = Amocrm::Resources::EntityNotesByParent.new(client: self)
  @events = Amocrm::Resources::Events.new(client: self)
  @leads = Amocrm::Resources::Leads.new(client: self)
  @pipeline_statuses = Amocrm::Resources::PipelineStatuses.new(client: self)
  @pipelines = Amocrm::Resources::Pipelines.new(client: self)
  @roles = Amocrm::Resources::Roles.new(client: self)
  @salesbot = Amocrm::Resources::Salesbot.new(client: self)
  @short_links = Amocrm::Resources::ShortLinks.new(client: self)
  @sources = Amocrm::Resources::Sources.new(client: self)
  @tags = Amocrm::Resources::Tags.new(client: self)
  @talks = Amocrm::Resources::Talks.new(client: self)
  @tasks = Amocrm::Resources::Tasks.new(client: self)
  @unsorted_leads = Amocrm::Resources::UnsortedLeads.new(client: self)
  @users = Amocrm::Resources::Users.new(client: self)
  @webhooks = Amocrm::Resources::Webhooks.new(client: self)
  @website_buttons = Amocrm::Resources::WebsiteButtons.new(client: self)
  @widget_bot_continue = Amocrm::Resources::WidgetBotContinue.new(client: self)
  @widgets = Amocrm::Resources::Widgets.new(client: self)
end

Instance Attribute Details

#accountAmocrm::Resources::Account (readonly)



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

def 
  @account
end

#callsAmocrm::Resources::Calls (readonly)



28
29
30
# File 'lib/amocrm/client.rb', line 28

def calls
  @calls
end

#catalog_elementsAmocrm::Resources::CatalogElements (readonly)



31
32
33
# File 'lib/amocrm/client.rb', line 31

def catalog_elements
  @catalog_elements
end

#catalogsAmocrm::Resources::Catalogs (readonly)



34
35
36
# File 'lib/amocrm/client.rb', line 34

def catalogs
  @catalogs
end

#companiesAmocrm::Resources::Companies (readonly)



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

def companies
  @companies
end

#contact_chatsAmocrm::Resources::ContactChats (readonly)



40
41
42
# File 'lib/amocrm/client.rb', line 40

def contact_chats
  @contact_chats
end

#contactsAmocrm::Resources::Contacts (readonly)



43
44
45
# File 'lib/amocrm/client.rb', line 43

def contacts
  @contacts
end

#custom_field_groupsAmocrm::Resources::CustomFieldGroups (readonly)



46
47
48
# File 'lib/amocrm/client.rb', line 46

def custom_field_groups
  @custom_field_groups
end

#custom_fieldsAmocrm::Resources::CustomFields (readonly)



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

def custom_fields
  @custom_fields
end

#customer_bonus_pointsAmocrm::Resources::CustomerBonusPoints (readonly)



52
53
54
# File 'lib/amocrm/client.rb', line 52

def customer_bonus_points
  @customer_bonus_points
end

#customer_segmentsAmocrm::Resources::CustomerSegments (readonly)



55
56
57
# File 'lib/amocrm/client.rb', line 55

def customer_segments
  @customer_segments
end

#customer_statusesAmocrm::Resources::CustomerStatuses (readonly)



58
59
60
# File 'lib/amocrm/client.rb', line 58

def customer_statuses
  @customer_statuses
end

#customer_transactionsAmocrm::Resources::CustomerTransactions (readonly)



61
62
63
# File 'lib/amocrm/client.rb', line 61

def customer_transactions
  @customer_transactions
end

#customersAmocrm::Resources::Customers (readonly)



64
65
66
# File 'lib/amocrm/client.rb', line 64

def customers
  @customers
end

#customers_modeAmocrm::Resources::CustomersMode (readonly)



67
68
69
# File 'lib/amocrm/client.rb', line 67

def customers_mode
  @customers_mode
end

#entity_followersAmocrm::Resources::EntityFollowers (readonly)



70
71
72
# File 'lib/amocrm/client.rb', line 70

def entity_followers
  @entity_followers
end


73
74
75
# File 'lib/amocrm/client.rb', line 73

def entity_links
  @entity_links
end

#entity_notesAmocrm::Resources::EntityNotes (readonly)



76
77
78
# File 'lib/amocrm/client.rb', line 76

def entity_notes
  @entity_notes
end

#entity_notes_by_parentAmocrm::Resources::EntityNotesByParent (readonly)



79
80
81
# File 'lib/amocrm/client.rb', line 79

def entity_notes_by_parent
  @entity_notes_by_parent
end

#eventsAmocrm::Resources::Events (readonly)



82
83
84
# File 'lib/amocrm/client.rb', line 82

def events
  @events
end

#leadsAmocrm::Resources::Leads (readonly)



85
86
87
# File 'lib/amocrm/client.rb', line 85

def leads
  @leads
end

#pipeline_statusesAmocrm::Resources::PipelineStatuses (readonly)



88
89
90
# File 'lib/amocrm/client.rb', line 88

def pipeline_statuses
  @pipeline_statuses
end

#pipelinesAmocrm::Resources::Pipelines (readonly)



91
92
93
# File 'lib/amocrm/client.rb', line 91

def pipelines
  @pipelines
end

#rolesAmocrm::Resources::Roles (readonly)



94
95
96
# File 'lib/amocrm/client.rb', line 94

def roles
  @roles
end

#salesbotAmocrm::Resources::Salesbot (readonly)



97
98
99
# File 'lib/amocrm/client.rb', line 97

def salesbot
  @salesbot
end


100
101
102
# File 'lib/amocrm/client.rb', line 100

def short_links
  @short_links
end

#sourcesAmocrm::Resources::Sources (readonly)



103
104
105
# File 'lib/amocrm/client.rb', line 103

def sources
  @sources
end

#subdomainString (readonly)

Returns:

  • (String)


22
23
24
# File 'lib/amocrm/client.rb', line 22

def subdomain
  @subdomain
end

#tagsAmocrm::Resources::Tags (readonly)



106
107
108
# File 'lib/amocrm/client.rb', line 106

def tags
  @tags
end

#talksAmocrm::Resources::Talks (readonly)



109
110
111
# File 'lib/amocrm/client.rb', line 109

def talks
  @talks
end

#tasksAmocrm::Resources::Tasks (readonly)



112
113
114
# File 'lib/amocrm/client.rb', line 112

def tasks
  @tasks
end

#tokenString (readonly)

Returns:

  • (String)


19
20
21
# File 'lib/amocrm/client.rb', line 19

def token
  @token
end

#unsorted_leadsAmocrm::Resources::UnsortedLeads (readonly)



115
116
117
# File 'lib/amocrm/client.rb', line 115

def unsorted_leads
  @unsorted_leads
end

#usersAmocrm::Resources::Users (readonly)



118
119
120
# File 'lib/amocrm/client.rb', line 118

def users
  @users
end

#webhooksAmocrm::Resources::Webhooks (readonly)



121
122
123
# File 'lib/amocrm/client.rb', line 121

def webhooks
  @webhooks
end

#website_buttonsAmocrm::Resources::WebsiteButtons (readonly)



124
125
126
# File 'lib/amocrm/client.rb', line 124

def website_buttons
  @website_buttons
end

#widget_bot_continueAmocrm::Resources::WidgetBotContinue (readonly)



127
128
129
# File 'lib/amocrm/client.rb', line 127

def widget_bot_continue
  @widget_bot_continue
end

#widgetsAmocrm::Resources::Widgets (readonly)



130
131
132
# File 'lib/amocrm/client.rb', line 130

def widgets
  @widgets
end