Class: Ordrin::APIs

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key, servers, restaurant_url = nil, user_url = nil, order_url = nil) ⇒ APIs

Arguments: api_key – The developer’s API key servers – How the server URLs should be set. Must be :production, :test, or :custom restaurant_url – The base url for the restaurant API. Can only be set if servers==:custom. user_url – The base url for the user API. Can only be set if servers==:custom. order_url – The base url for the order API. Can only be set if servers==:custom.



22
23
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
# File 'lib/ordrin.rb', line 22

def initialize(api_key, servers, restaurant_url=nil, user_url=nil, order_url=nil)
  @api_key = api_key
  if servers!=:custom
    unless restaurant_url.nil? and user_url.nil? and order_url.nil?
      raise ArgumentError.new("Individual URL parameters can only be set if servers is set to :custom")
    end
  end
  if servers==:production
    restaurant_url = "https://r.ordr.in/"
    user_url = "https://u.ordr.in/"
    order_url = "https://o.ordr.in/"
  elsif servers==:test
    restaurant_url = "https://r-test.ordr.in/"
    user_url = "https://u-test.ordr.in/"
    order_url = "https://o-test.ordr.in/"
  elsif servers!=:custom
    raise ArgumentError.new("servers must be set to :production, :test, or :custom")
  end
  unless restaurant_url.nil?
    @restaurant = RestaurantApi.new(api_key, restaurant_url)
  end
  unless user_url.nil?
    @user = UserApi.new(api_key, user_url)
  end
  unless order_url.nil?
    @order = OrderApi.new(api_key, order_url)
  end
end

Instance Attribute Details

#orderObject (readonly)

Returns the value of attribute order.



9
10
11
# File 'lib/ordrin.rb', line 9

def order
  @order
end

#restaurantObject (readonly)

Returns the value of attribute restaurant.



9
10
11
# File 'lib/ordrin.rb', line 9

def restaurant
  @restaurant
end

#userObject (readonly)

Returns the value of attribute user.



9
10
11
# File 'lib/ordrin.rb', line 9

def user
  @user
end

Instance Method Details

#configObject



51
52
53
54
55
56
# File 'lib/ordrin.rb', line 51

def config
  return {"API key" => api_key,
    "Restaurant URL" => @restaurant.base_url,
    "User URL" => @user.base_url,
    "Order URL" => @order.base_url}
end