Class: BridgeInteractive::API

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server_token, api_type: nil) ⇒ API

Returns a new instance of API.



17
18
19
20
21
22
23
24
25
26
# File 'lib/bridge_interactive/api.rb', line 17

def initialize(server_token, api_type: nil)
  @client = HTTPClient.new
  @server_token = server_token

  # Use the api_type passed in, or fall back to the globally configured api_type
  @api_type = api_type || BridgeInteractive.configuration.api_type

  # Apply global configuration settings to the client
  @client.connect_timeout = BridgeInteractive.configuration.timeout if BridgeInteractive.configuration
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



15
16
17
# File 'lib/bridge_interactive/api.rb', line 15

def client
  @client
end

#server_tokenObject (readonly)

Returns the value of attribute server_token.



15
16
17
# File 'lib/bridge_interactive/api.rb', line 15

def server_token
  @server_token
end

Instance Method Details

#datasetsObject

Fetch dataset resource



29
30
31
32
33
34
35
# File 'lib/bridge_interactive/api.rb', line 29

def datasets
  if @api_type == :bridge
    Bridge::Dataset.new(@client, @server_token)
  else
    log_and_return_error('datasets', 'Bridge')
  end
end

#lookupObject

Fetch lookup resource



38
39
40
41
42
43
44
# File 'lib/bridge_interactive/api.rb', line 38

def lookup
  if @api_type == :reso
    Reso::Lookup.new(@client, @server_token)
  else
    log_and_return_error('lookup', 'RESO')
  end
end

#member(api_type: nil) ⇒ Object Also known as: agents

Fetch member resource, allowing custom api_type to be passed



47
48
49
50
# File 'lib/bridge_interactive/api.rb', line 47

def member(api_type: nil)
  selected_api_type = api_type || @api_type
  selected_api_type == :bridge ? Bridge::Agent.new(@client, @server_token) : Reso::Member.new(@client, @server_token)
end

#offices(api_type: nil) ⇒ Object Also known as: office

Fetch office resource, allowing custom api_type to be passed



55
56
57
58
# File 'lib/bridge_interactive/api.rb', line 55

def offices(api_type: nil)
  selected_api_type = api_type || @api_type
  selected_api_type == :bridge ? Bridge::Office.new(@client, @server_token) : Reso::Office.new(@client, @server_token)
end

#open_houses(api_type: nil) ⇒ Object Also known as: open_house

Fetch open house resource, allowing custom api_type to be passed



63
64
65
66
# File 'lib/bridge_interactive/api.rb', line 63

def open_houses(api_type: nil)
  selected_api_type = api_type || @api_type
  selected_api_type == :bridge ? Bridge::OpenHouse.new(@client, @server_token) : Reso::OpenHouse.new(@client, @server_token)
end

#property(api_type: nil) ⇒ Object Also known as: listings

Fetch property resource, allowing custom api_type to be passed



71
72
73
74
# File 'lib/bridge_interactive/api.rb', line 71

def property(api_type: nil)
  selected_api_type = api_type || @api_type
  selected_api_type == :bridge ? Bridge::Listing.new(@client, @server_token) : Reso::Property.new(@client, @server_token)
end