Class: Sellsy::Address
- Inherits:
-
Object
- Object
- Sellsy::Address
- Defined in:
- lib/sellsy/address.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
Returns the value of attribute address.
-
#country ⇒ Object
Returns the value of attribute country.
-
#id ⇒ Object
Returns the value of attribute id.
-
#linkedid ⇒ Object
Returns the value of attribute linkedid.
-
#linkedtype ⇒ Object
Returns the value of attribute linkedtype.
-
#name ⇒ Object
Returns the value of attribute name.
-
#postal_code ⇒ Object
Returns the value of attribute postal_code.
-
#town ⇒ Object
Returns the value of attribute town.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#address ⇒ Object
Returns the value of attribute address.
5 6 7 |
# File 'lib/sellsy/address.rb', line 5 def address @address end |
#country ⇒ Object
Returns the value of attribute country.
5 6 7 |
# File 'lib/sellsy/address.rb', line 5 def country @country end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/sellsy/address.rb', line 5 def id @id end |
#linkedid ⇒ Object
Returns the value of attribute linkedid.
5 6 7 |
# File 'lib/sellsy/address.rb', line 5 def linkedid @linkedid end |
#linkedtype ⇒ Object
Returns the value of attribute linkedtype.
5 6 7 |
# File 'lib/sellsy/address.rb', line 5 def linkedtype @linkedtype end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/sellsy/address.rb', line 5 def name @name end |
#postal_code ⇒ Object
Returns the value of attribute postal_code.
5 6 7 |
# File 'lib/sellsy/address.rb', line 5 def postal_code @postal_code end |
#town ⇒ Object
Returns the value of attribute town.
5 6 7 |
# File 'lib/sellsy/address.rb', line 5 def town @town end |
Class Method Details
.all ⇒ Object
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
#create ⇒ Object
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_params ⇒ Object
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 |