Class: LockstepSdk::LockstepApi

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.new(env) ⇒ Object

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 (/)



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/LockstepApi.rb', line 25

def self.new(env)
    @version = "2021.39"
    @env = case env
        when "sbx"
            "https://api.sbx.lockstep.io/"
        when "prd"
            "https://api.lockstep.io/"
        else
            env
        end
        
    # Construct all the clients
    @activities = Activities.new(self)
    @apikeys = ApiKeys.new(self)
    @appenrollments = AppEnrollments.new(self)
    @applications = Applications.new(self)
    @attachments = Attachments.new(self)
    @codedefinitions = CodeDefinitions.new(self)
    @companies = Companies.new(self)
    @contacts = Contacts.new(self)
    @creditmemoapplied = CreditMemoApplied.new(self)
    @currencies = Currencies.new(self)
    @customfielddefinitions = CustomFieldDefinitions.new(self)
    @customfieldvalues = CustomFieldValues.new(self)
    @definitions = Definitions.new(self)
    @emails = Emails.new(self)
    @invoicehistory = InvoiceHistory.new(self)
    @invoices = Invoices.new(self)
    @leads = Leads.new(self)
    @migration = Migration.new(self)
    @notes = Notes.new(self)
    @paymentapplications = PaymentApplications.new(self)
    @payments = Payments.new(self)
    @provisioning = Provisioning.new(self)
    @reports = Reports.new(self)
    @status = Status.new(self)
    @sync = Sync.new(self)
    @useraccounts = UserAccounts.new(self)
    @userroles = UserRoles.new(self)
end

Instance Method Details

#request(method, path, body, options = {}) ⇒ Object

Send a request to the API and return the results

Sends a request to the



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/LockstepApi.rb', line 85

def request(method, path, body, options={})
    
    url = URI(@env + path)
    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
    request["Accept"] = 'application/json'

    # Which authentication are we using?
    if @api_key != nil 
        request["Api-Key"] = @api_key
    end
    if @api_key != nil 
        request["Authorization"] = 'Bearer ' + @bearer_token
    end

    # Send the request
    response = http.request(request)
    puts response.read_body
end

#with_api_key(api_key) ⇒ Object

Configure this API client to use API key authentication

Parameters:



69
70
71
72
# File 'lib/LockstepApi.rb', line 69

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

#with_bearer_token(bearer_token) ⇒ Object

Configure this API client to use JWT Bearer Token authentication

Parameters:



77
78
79
80
# File 'lib/LockstepApi.rb', line 77

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