Class: AppStoreInfo::API

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#idObject

Returns the value of attribute id.



10
11
12
# File 'lib/appstore_info/api.rb', line 10

def id
  @id
end

#urlObject

Returns the value of attribute url.



10
11
12
# File 'lib/appstore_info/api.rb', line 10

def url
  @url
end

Instance Method Details

#parseObject



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