Class: ShedCloud::PartnerApi::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/shedcloud/partner_api/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(auth:, environment: nil, base_url: nil, transport: HttpTransport.new, timeout_seconds: 30.0, user_agent: 'shedcloud-ruby/partner-api', token_skew_seconds: 60) ⇒ Client

Returns a new instance of Client.

Raises:

  • (ArgumentError)


24
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
# File 'lib/shedcloud/partner_api/client.rb', line 24

def initialize(auth:, environment: nil, base_url: nil, transport: HttpTransport.new, timeout_seconds: 30.0,
               user_agent: 'shedcloud-ruby/partner-api', token_skew_seconds: 60)
  raise ArgumentError, 'Client: auth is required' unless auth.is_a?(Auth)

  auth.validate!

  @base_url = Hosts.resolve_base_url(base_url: base_url, environment: environment)
  @auth_provider = AuthProvider.new(
    base_url: @base_url,
    auth: auth,
    transport: transport,
    token_skew_seconds: token_skew_seconds
  )

  @http = HttpClient.new(
    base_url: @base_url,
    get_access_token: -> { @auth_provider.access_token },
    transport: transport,
    user_agent: user_agent
  )

  @lot_stock = Resources::LotStock.new(@http)
  @stock_templates = Resources::StockTemplates.new(@http)
  @leads = Resources::Leads.new(@http)
  @quotes = Resources::Quotes.new(@http)
  @orders = Resources::Orders.new(@http)
  @work_orders = Resources::WorkOrders.new(@http)
  @locations = Resources::Locations.new(@http)
  @customers = Resources::Customers.new(@http)
  @domains = Resources::Domains.new(@http)
  @agreements = Resources::Agreements.new(@http)
  @products = Resources::Products.new(@http)
  @users = Resources::Users.new(@http)
  @payments = Resources::Payments.new(@http)
  @documents = Resources::Documents.new(@http)
  @events = Resources::Events.new(@http)
  @configurator_sessions = Resources::ConfiguratorSessions.new(@http)
end

Instance Attribute Details

#agreementsObject (readonly)

Returns the value of attribute agreements.



6
7
8
# File 'lib/shedcloud/partner_api/client.rb', line 6

def agreements
  @agreements
end

#base_urlObject (readonly)

Returns the value of attribute base_url.



6
7
8
# File 'lib/shedcloud/partner_api/client.rb', line 6

def base_url
  @base_url
end

#configurator_sessionsObject (readonly)

Returns the value of attribute configurator_sessions.



6
7
8
# File 'lib/shedcloud/partner_api/client.rb', line 6

def configurator_sessions
  @configurator_sessions
end

#customersObject (readonly)

Returns the value of attribute customers.



6
7
8
# File 'lib/shedcloud/partner_api/client.rb', line 6

def customers
  @customers
end

#documentsObject (readonly)

Returns the value of attribute documents.



6
7
8
# File 'lib/shedcloud/partner_api/client.rb', line 6

def documents
  @documents
end

#domainsObject (readonly)

Returns the value of attribute domains.



6
7
8
# File 'lib/shedcloud/partner_api/client.rb', line 6

def domains
  @domains
end

#eventsObject (readonly)

Returns the value of attribute events.



6
7
8
# File 'lib/shedcloud/partner_api/client.rb', line 6

def events
  @events
end

#leadsObject (readonly)

Returns the value of attribute leads.



6
7
8
# File 'lib/shedcloud/partner_api/client.rb', line 6

def leads
  @leads
end

#locationsObject (readonly)

Returns the value of attribute locations.



6
7
8
# File 'lib/shedcloud/partner_api/client.rb', line 6

def locations
  @locations
end

#lot_stockObject (readonly)

Returns the value of attribute lot_stock.



6
7
8
# File 'lib/shedcloud/partner_api/client.rb', line 6

def lot_stock
  @lot_stock
end

#ordersObject (readonly)

Returns the value of attribute orders.



6
7
8
# File 'lib/shedcloud/partner_api/client.rb', line 6

def orders
  @orders
end

#paymentsObject (readonly)

Returns the value of attribute payments.



6
7
8
# File 'lib/shedcloud/partner_api/client.rb', line 6

def payments
  @payments
end

#productsObject (readonly)

Returns the value of attribute products.



6
7
8
# File 'lib/shedcloud/partner_api/client.rb', line 6

def products
  @products
end

#quotesObject (readonly)

Returns the value of attribute quotes.



6
7
8
# File 'lib/shedcloud/partner_api/client.rb', line 6

def quotes
  @quotes
end

#stock_templatesObject (readonly)

Returns the value of attribute stock_templates.



6
7
8
# File 'lib/shedcloud/partner_api/client.rb', line 6

def stock_templates
  @stock_templates
end

#usersObject (readonly)

Returns the value of attribute users.



6
7
8
# File 'lib/shedcloud/partner_api/client.rb', line 6

def users
  @users
end

#work_ordersObject (readonly)

Returns the value of attribute work_orders.



6
7
8
# File 'lib/shedcloud/partner_api/client.rb', line 6

def work_orders
  @work_orders
end

Instance Method Details

#meObject



63
64
65
# File 'lib/shedcloud/partner_api/client.rb', line 63

def me
  @http.request('GET', '/partner/v1/me') || {}
end

#refresh_access_tokenObject



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

def refresh_access_token
  @auth_provider.refresh
end