Class: PQSDK::City
- Inherits:
-
RemoteObject
- Object
- RemoteObject
- PQSDK::City
- Defined in:
- lib/pqsdk/city.rb
Overview
The City class provides an interface for crawlers to the v1/cities api endpoint.
Instance Attribute Summary collapse
-
#country ⇒ Object
Returns the value of attribute country.
-
#county ⇒ Object
Returns the value of attribute county.
-
#id ⇒ Object
Returns the value of attribute id.
-
#inhabitants ⇒ Object
Returns the value of attribute inhabitants.
-
#is_county ⇒ Object
Returns the value of attribute is_county.
-
#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
Methods inherited from RemoteObject
all, #create, #create!, from_hash, get, #persisted?, #save, #save!, #update, #update!
Instance Attribute Details
#country ⇒ Object
Returns the value of attribute country.
9 10 11 |
# File 'lib/pqsdk/city.rb', line 9 def country @country end |
#county ⇒ Object
Returns the value of attribute county.
9 10 11 |
# File 'lib/pqsdk/city.rb', line 9 def county @county end |
#id ⇒ Object
Returns the value of attribute id.
9 10 11 |
# File 'lib/pqsdk/city.rb', line 9 def id @id end |
#inhabitants ⇒ Object
Returns the value of attribute inhabitants.
9 10 11 |
# File 'lib/pqsdk/city.rb', line 9 def inhabitants @inhabitants end |
#is_county ⇒ Object
Returns the value of attribute is_county.
9 10 11 |
# File 'lib/pqsdk/city.rb', line 9 def is_county @is_county end |
#latitude ⇒ Object
Returns the value of attribute latitude.
9 10 11 |
# File 'lib/pqsdk/city.rb', line 9 def latitude @latitude end |
#longitude ⇒ Object
Returns the value of attribute longitude.
9 10 11 |
# File 'lib/pqsdk/city.rb', line 9 def longitude @longitude end |
#name ⇒ Object
Returns the value of attribute name.
9 10 11 |
# File 'lib/pqsdk/city.rb', line 9 def name @name end |
#state ⇒ Object
Returns the value of attribute state.
9 10 11 |
# File 'lib/pqsdk/city.rb', line 9 def state @state end |
Class Method Details
.find(name) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/pqsdk/city.rb', line 20 def self.find(name) res = RestLayer.get(@endpoint, q: name) if res[0] == 200 from_hash res[1] elsif res[0] == 404 nil else raise "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 = find(name) return city if city city = City.new city.name = name city.create! city end |
Instance Method Details
#attributes ⇒ Object
13 14 15 16 17 18 |
# File 'lib/pqsdk/city.rb', line 13 def attributes { 'name' => nil, 'inhabitants' => nil, 'latitude' => nil, 'longitude' => nil, 'state' => nil, 'country' => nil } end |