Class: LockstepSdk::LockstepApi

Inherits:
Object
  • Object
show all
Defined in:
lib/lockstep_sdk/lockstep_api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ LockstepApi

Construct a new Lockstep API client targeting the specified server.

Parameters:

  • env (string)

    Either “sbx”, “prd”, or the URI of the server, ending in a slash (/)



145
146
147
148
149
150
151
152
153
154
155
156
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
# File 'lib/lockstep_sdk/lockstep_api.rb', line 145

def initialize(env)
    @version = "2022.4.32.0"
    @env = case env
        when "sbx"
            "https://api.sbx.lockstep.io/"
        when "prd"
            "https://api.lockstep.io/"
        else
            env
        end
        
    # Construct all the clients
    @activities = ActivitiesClient.new(self)
    @api_keys = ApiKeysClient.new(self)
    @app_enrollments = AppEnrollmentsClient.new(self)
    @applications = ApplicationsClient.new(self)
    @attachments = AttachmentsClient.new(self)
    @code_definitions = CodeDefinitionsClient.new(self)
    @companies = CompaniesClient.new(self)
    @contacts = ContactsClient.new(self)
    @credit_memo_applied = CreditMemoAppliedClient.new(self)
    @currencies = CurrenciesClient.new(self)
    @custom_field_definitions = CustomFieldDefinitionsClient.new(self)
    @custom_field_values = CustomFieldValuesClient.new(self)
    @definitions = DefinitionsClient.new(self)
    @emails = EmailsClient.new(self)
    @invoice_history = InvoiceHistoryClient.new(self)
    @invoices = InvoicesClient.new(self)
    @leads = LeadsClient.new(self)
    @notes = NotesClient.new(self)
    @payment_applications = PaymentApplicationsClient.new(self)
    @payments = PaymentsClient.new(self)
    @provisioning = ProvisioningClient.new(self)
    @reports = ReportsClient.new(self)
    @status = StatusClient.new(self)
    @sync = SyncClient.new(self)
    @user_accounts = UserAccountsClient.new(self)
    @user_roles = UserRolesClient.new(self)
end

Instance Attribute Details

#activitiesActivitiesClient

Returns Client object for Activities endpoints.

Returns:



38
39
40
# File 'lib/lockstep_sdk/lockstep_api.rb', line 38

def activities
  @activities
end

#api_keysApiKeysClient

Returns Client object for ApiKeys endpoints.

Returns:



42
43
44
# File 'lib/lockstep_sdk/lockstep_api.rb', line 42

def api_keys
  @api_keys
end

#app_enrollmentsAppEnrollmentsClient

Returns Client object for AppEnrollments endpoints.

Returns:



46
47
48
# File 'lib/lockstep_sdk/lockstep_api.rb', line 46

def app_enrollments
  @app_enrollments
end

#applicationsApplicationsClient

Returns Client object for Applications endpoints.

Returns:



50
51
52
# File 'lib/lockstep_sdk/lockstep_api.rb', line 50

def applications
  @applications
end

#attachmentsAttachmentsClient

Returns Client object for Attachments endpoints.

Returns:



54
55
56
# File 'lib/lockstep_sdk/lockstep_api.rb', line 54

def attachments
  @attachments
end

#code_definitionsCodeDefinitionsClient

Returns Client object for CodeDefinitions endpoints.

Returns:



58
59
60
# File 'lib/lockstep_sdk/lockstep_api.rb', line 58

def code_definitions
  @code_definitions
end

#companiesCompaniesClient

Returns Client object for Companies endpoints.

Returns:



62
63
64
# File 'lib/lockstep_sdk/lockstep_api.rb', line 62

def companies
  @companies
end

#contactsContactsClient

Returns Client object for Contacts endpoints.

Returns:



66
67
68
# File 'lib/lockstep_sdk/lockstep_api.rb', line 66

def contacts
  @contacts
end

#credit_memo_appliedCreditMemoAppliedClient

Returns Client object for CreditMemoApplied endpoints.

Returns:



70
71
72
# File 'lib/lockstep_sdk/lockstep_api.rb', line 70

def credit_memo_applied
  @credit_memo_applied
end

#currenciesCurrenciesClient

Returns Client object for Currencies endpoints.

Returns:



74
75
76
# File 'lib/lockstep_sdk/lockstep_api.rb', line 74

def currencies
  @currencies
end

#custom_field_definitionsCustomFieldDefinitionsClient

Returns Client object for CustomFieldDefinitions endpoints.

Returns:



78
79
80
# File 'lib/lockstep_sdk/lockstep_api.rb', line 78

def custom_field_definitions
  @custom_field_definitions
end

#custom_field_valuesCustomFieldValuesClient

Returns Client object for CustomFieldValues endpoints.

Returns:



82
83
84
# File 'lib/lockstep_sdk/lockstep_api.rb', line 82

def custom_field_values
  @custom_field_values
end

#definitionsDefinitionsClient

Returns Client object for Definitions endpoints.

Returns:



86
87
88
# File 'lib/lockstep_sdk/lockstep_api.rb', line 86

def definitions
  @definitions
end

#emailsEmailsClient

Returns Client object for Emails endpoints.

Returns:



90
91
92
# File 'lib/lockstep_sdk/lockstep_api.rb', line 90

def emails
  @emails
end

#envString

Returns The name or URL of the environment.

Returns:

  • (String)

    The name or URL of the environment



34
35
36
# File 'lib/lockstep_sdk/lockstep_api.rb', line 34

def env
  @env
end

#invoice_historyInvoiceHistoryClient

Returns Client object for InvoiceHistory endpoints.

Returns:



94
95
96
# File 'lib/lockstep_sdk/lockstep_api.rb', line 94

def invoice_history
  @invoice_history
end

#invoicesInvoicesClient

Returns Client object for Invoices endpoints.

Returns:



98
99
100
# File 'lib/lockstep_sdk/lockstep_api.rb', line 98

def invoices
  @invoices
end

#leadsLeadsClient

Returns Client object for Leads endpoints.

Returns:



102
103
104
# File 'lib/lockstep_sdk/lockstep_api.rb', line 102

def leads
  @leads
end

#notesNotesClient

Returns Client object for Notes endpoints.

Returns:



106
107
108
# File 'lib/lockstep_sdk/lockstep_api.rb', line 106

def notes
  @notes
end

#payment_applicationsPaymentApplicationsClient

Returns Client object for PaymentApplications endpoints.

Returns:



110
111
112
# File 'lib/lockstep_sdk/lockstep_api.rb', line 110

def payment_applications
  @payment_applications
end

#paymentsPaymentsClient

Returns Client object for Payments endpoints.

Returns:



114
115
116
# File 'lib/lockstep_sdk/lockstep_api.rb', line 114

def payments
  @payments
end

#provisioningProvisioningClient

Returns Client object for Provisioning endpoints.

Returns:



118
119
120
# File 'lib/lockstep_sdk/lockstep_api.rb', line 118

def provisioning
  @provisioning
end

#reportsReportsClient

Returns Client object for Reports endpoints.

Returns:



122
123
124
# File 'lib/lockstep_sdk/lockstep_api.rb', line 122

def reports
  @reports
end

#statusStatusClient

Returns Client object for Status endpoints.

Returns:



126
127
128
# File 'lib/lockstep_sdk/lockstep_api.rb', line 126

def status
  @status
end

#syncSyncClient

Returns Client object for Sync endpoints.

Returns:

  • (SyncClient)

    Client object for Sync endpoints



130
131
132
# File 'lib/lockstep_sdk/lockstep_api.rb', line 130

def sync
  @sync
end

#user_accountsUserAccountsClient

Returns Client object for UserAccounts endpoints.

Returns:



134
135
136
# File 'lib/lockstep_sdk/lockstep_api.rb', line 134

def user_accounts
  @user_accounts
end

#user_rolesUserRolesClient

Returns Client object for UserRoles endpoints.

Returns:



138
139
140
# File 'lib/lockstep_sdk/lockstep_api.rb', line 138

def user_roles
  @user_roles
end

#versionString

Returns The version number of this Lockstep API client.

Returns:

  • (String)

    The version number of this Lockstep API client



30
31
32
# File 'lib/lockstep_sdk/lockstep_api.rb', line 30

def version
  @version
end

Instance Method Details

#request(method, path, body, params) ⇒ Object

Send a request to the API and return the results

Sends a request to the



215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# File 'lib/lockstep_sdk/lockstep_api.rb', line 215

def request(method, path, body, params)

    url = URI(@env + path)
    if !params.nil?  
        url.query = URI.encode_www_form(params)
    end
    
    http = Net::HTTP.new(url.host, url.port)
    http.use_ssl = true
    
    request = case method
        when :get
            Net::HTTP::Get.new(url)
        when :post
            Net::HTTP::Post.new(url)
        when :patch
            Net::HTTP::Patch.new(url)
        when :put
            Net::HTTP::Put.new(url)
        when :delete
            Net::HTTP::Delete.new(url)
        end
        
    # Set headers and body for request
    request["Accept"] = 'application/json'
    request["Content-Type"] = 'application/*+json'
    request["SdkType"] = 'Ruby'
    request["SdkVersion"] = '2022.4.32.0'
    request["MachineName"] = Socket.gethostname
    request.body = body

    # If there is an application name
    if @app_name != nil
        request["ApplicationName"] = @app_name
    end

    # Which authentication are we using?
    if @api_key != nil 
      request["Api-Key"] = @api_key
    end
    if @bearer_token != nil 
      request["Authorization"] = 'Bearer ' + @bearer_token
    end
    
    # Send the request
    response = http.request(request)
    response.read_body
end

#with_api_key(api_key) ⇒ Object

Configure this API client to use API key authentication

Parameters:



189
190
191
192
# File 'lib/lockstep_sdk/lockstep_api.rb', line 189

def with_api_key(api_key)
    @bearer_token = nil
    @api_key = api_key
end

#with_app_name(app_name) ⇒ Object

Configure this API to use an application name

Parameters:

  • app_name (string)

    The name of the application



207
208
209
# File 'lib/lockstep_sdk/lockstep_api.rb', line 207

def with_app_name(app_name)
    @app_name = app_name
end

#with_bearer_token(bearer_token) ⇒ Object

Configure this API client to use JWT Bearer Token authentication

Parameters:



198
199
200
201
# File 'lib/lockstep_sdk/lockstep_api.rb', line 198

def with_bearer_token(bearer_token)
    @api_key = nil
    @bearer_token = bearer_token
end