Class: Vng::Franchise

Inherits:
Resource show all
Defined in:
lib/vng/franchise.rb

Overview

Provides methods to interact with Vonigo franchises.

Constant Summary collapse

PATH =
'/api/v1/resources/franchises/'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, name: nil, gmt_offset: nil) ⇒ Franchise

Returns a new instance of Franchise.



10
11
12
13
14
# File 'lib/vng/franchise.rb', line 10

def initialize(id:, name: nil, gmt_offset: nil)
  @id = id
  @name = name
  @gmt_offset = gmt_offset
end

Instance Attribute Details

#gmt_offsetObject (readonly)

Returns the value of attribute gmt_offset.



8
9
10
# File 'lib/vng/franchise.rb', line 8

def gmt_offset
  @gmt_offset
end

#idObject (readonly)

Returns the value of attribute id.



8
9
10
# File 'lib/vng/franchise.rb', line 8

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/vng/franchise.rb', line 8

def name
  @name
end

Class Method Details

.allObject



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/vng/franchise.rb', line 29

def self.all
  data = request path: PATH

  data['Franchises'].filter do |franchise|
    franchise['isActive']
  end.map do |franchise|
    id = franchise['franchiseID']
    name = franchise['franchiseName']
    gmt_offset = franchise['gmtOffsetFranchise']

    new id: id, name: name, gmt_offset: gmt_offset
  end
end

.find_by(zip:) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/vng/franchise.rb', line 17

def self.find_by(zip:)
  body = {
    method: '1',
    zip: zip,
  }

  data = request path: Vng::Availability::PATH, body: body

  franchise_id = data['Ids']['franchiseID']
  new(id: franchise_id) unless franchise_id == '0'
end