Class: PQSDK::City
- Inherits:
-
Object
- Object
- PQSDK::City
- Defined in:
- lib/pqsdk/city.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#inhabitants ⇒ Object
Returns the value of attribute inhabitants.
-
#latitude ⇒ Object
Returns the value of attribute latitude.
-
#longitude ⇒ Object
Returns the value of attribute longitude.
-
#name ⇒ Object
Returns the value of attribute name.
-
#state ⇒ Object
Returns the value of attribute state.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/pqsdk/city.rb', line 3 def id @id end |
#inhabitants ⇒ Object
Returns the value of attribute inhabitants.
3 4 5 |
# File 'lib/pqsdk/city.rb', line 3 def inhabitants @inhabitants end |
#latitude ⇒ Object
Returns the value of attribute latitude.
3 4 5 |
# File 'lib/pqsdk/city.rb', line 3 def latitude @latitude end |
#longitude ⇒ Object
Returns the value of attribute longitude.
3 4 5 |
# File 'lib/pqsdk/city.rb', line 3 def longitude @longitude end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/pqsdk/city.rb', line 3 def name @name end |
#state ⇒ Object
Returns the value of attribute state.
3 4 5 |
# File 'lib/pqsdk/city.rb', line 3 def state @state end |
Class Method Details
.all ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/pqsdk/city.rb', line 16 def self.all res = RestLayer.get('v1/cities', {}, {'Authorization' => "Bearer #{Token.access_token}" }) if res[0] == 200 cities = [] res[1].each do |city| cities << City.from_json(city) end return cities elsif res[0] == 404 nil else raise Exception.new("Unexpected HTTP status code #{res[0]}, #{res[1]}") end end |
.find(name) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/pqsdk/city.rb', line 5 def self.find(name) res = RestLayer.get('v1/cities', { q: name }, { 'Authorization' => "Bearer #{Token.access_token}" }) if res[0] == 200 City.from_json res[1] elsif res[0] == 404 nil else raise Exception.new("Unexpected HTTP status code #{res[0]}, #{res[1]}") end end |
.find_or_create(name) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/pqsdk/city.rb', line 31 def self.find_or_create(name) city = self.find(name) return city if city city = City.new city.name = name city.save city end |
Instance Method Details
#save ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/pqsdk/city.rb', line 42 def save res = RestLayer.post('v1/cities', { name: name }, { 'Authorization' => "Bearer #{Token.access_token}" }) if res[0] != 201 raise Exception.new("Unexpected HTTP status code #{res[0]}, #{res[1]}") else self.id = res[1]['id'] end end |