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

Returns a new instance of Franchise.



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

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

Instance Attribute Details

#cellObject (readonly)

Returns the value of attribute cell.



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

def cell
  @cell
end

#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

#phoneObject (readonly)

Returns the value of attribute phone.



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

def phone
  @phone
end

Class Method Details

.allObject



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/vng/franchise.rb', line 46

def self.all
  data = request path: PATH

  data.fetch('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



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/vng/franchise.rb', line 32

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

  data = request path: PATH, body: body

  email = value_for_field data, 9
  phone = value_for_field data, 18
  cell = value_for_field data, 1001
  new id: franchise_id, email: email, phone: phone, cell: cell
end

.find_by(zip:) ⇒ Object



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

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