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, email: nil) ⇒ Franchise

Returns a new instance of Franchise.



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

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

Instance Attribute Details

#emailObject (readonly)

Returns the value of attribute email.



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

def email
  @email
end

#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



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/vng/franchise.rb', line 41

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(franchise_id) ⇒ Object



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

def self.find(franchise_id)
  body = {
    method: '1',
    objectID: franchise_id,
  }

  data = request path: PATH, body: body
  email = value_for_field data, 9
  new id: franchise_id, email: email
end

.find_by(zip:) ⇒ Object



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

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

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

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