Class: Sellsy::Address

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#addressObject

Returns the value of attribute address.



5
6
7
# File 'lib/sellsy/address.rb', line 5

def address
  @address
end

#countryObject

Returns the value of attribute country.



5
6
7
# File 'lib/sellsy/address.rb', line 5

def country
  @country
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/sellsy/address.rb', line 5

def id
  @id
end

#linkedidObject

Returns the value of attribute linkedid.



5
6
7
# File 'lib/sellsy/address.rb', line 5

def linkedid
  @linkedid
end

#linkedtypeObject

Returns the value of attribute linkedtype.



5
6
7
# File 'lib/sellsy/address.rb', line 5

def linkedtype
  @linkedtype
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/sellsy/address.rb', line 5

def name
  @name
end

#postal_codeObject

Returns the value of attribute postal_code.



5
6
7
# File 'lib/sellsy/address.rb', line 5

def postal_code
  @postal_code
end

#townObject

Returns the value of attribute town.



5
6
7
# File 'lib/sellsy/address.rb', line 5

def town
  @town
end

Class Method Details

.allObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/sellsy/address.rb', line 45

def self.all
  command = {
      'method' => 'Addresses.getList',
      'params' => {}
  }

  response = MultiJson.load(Sellsy::Api.request command)

  addresses = []

  if response['response']
    response['response']['result'].each do |key, value|
      address = Address.new
      address.id = key
      address.address = [value['part1'] || '', value['part2'] || ''].select {|p| !p.blank?}.join("\n")
      address.town = value['town']
      address.country = value['countrycode'].downcase unless value['countrycode'].blank?
      address.linkedid = value['linkedid']
      address.linkedtype = value['linkedtype']
      address.postal_code = value['zip']
      addresses << address
    end
  end

  addresses
end

.find(id) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/sellsy/address.rb', line 20

def self.find(id)
  command = {
      'method' => 'Addresses.getOne',
      'params' => {
          'id' => id
      }
  }

  response = MultiJson.load(Sellsy::Api.request command)
  address = Address.new

  if response['response']
    value = response['response']
    address.id = key
    address.address = [value['part1'], value['part2'] || ''].select {|p| !p.blank?}.join("\n")
    address.town = value['town']
    address.country = value['countrycode'].downcase unless value['countrycode'].blank?
    address.linkedid = value['linkedid']
    address.linkedtype = value['linkedtype']
    address.postal_code = value['zip']
  end

  address
end

Instance Method Details

#createObject



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/sellsy/address.rb', line 7

def create
  command = {
      'method' => 'Addresses.create',
      'params' => to_params
  }

  response = MultiJson.load(Sellsy::Api.request command)

  @id = response['response']['address_id'] if response['response']

  response['status'] == 'success'
end

#to_paramsObject



72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/sellsy/address.rb', line 72

def to_params
  {
    'name' => 'Adresse principale',
    'part1' => @address.split(/(\r\n?)/)[0],
    'part2' => @address.split(/(\r\n?)/)[1],
    'zip' => @postal_code,
    'town' => @town,
    'countrycode' => @country.upcase,
    "linkedtype" => linkedtype,
    "linkedid" => linkedid
  }
end