Class: AppStoreInfo::API
- Inherits:
-
Object
- Object
- AppStoreInfo::API
- Defined in:
- lib/appstore_info/api.rb
Constant Summary collapse
- URL_TEMPLATE =
The URL to lookup an app. The first variable is the region (us, pt, kor, etc..) and the second one is the application id (i.e. 599015198).
'https://itunes.apple.com/%s/lookup?id=%s'.freeze
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(id, region = AppStoreInfo::DEFAULT_REGION) ⇒ API
constructor
A new instance of API.
- #parse ⇒ Object
Constructor Details
#initialize(id, region = AppStoreInfo::DEFAULT_REGION) ⇒ API
Returns a new instance of API.
12 13 14 15 16 |
# File 'lib/appstore_info/api.rb', line 12 def initialize(id, region = AppStoreInfo::DEFAULT_REGION) @id = id @region = region @url = format(URL_TEMPLATE, region, id) end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
10 11 12 |
# File 'lib/appstore_info/api.rb', line 10 def id @id end |
#url ⇒ Object
Returns the value of attribute url.
10 11 12 |
# File 'lib/appstore_info/api.rb', line 10 def url @url end |
Instance Method Details
#parse ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/appstore_info/api.rb', line 18 def parse response = Faraday.get(url) unless response.status == 200 && response.body raise ConnectionError, "Cound't connect to app store API" end parse_json(response.body) end |