apprank 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/apprank/app.rb +51 -36
  3. data/spec/app_spec.rb +7 -2
  4. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 77139758135e695d99945a2ec7655de1bc05e0d0
4
- data.tar.gz: b253389211a9491c55c6e0be4b6f052ef40ced3a
3
+ metadata.gz: d0dc98edfdf5566cc325fe4c2b4861da11378db2
4
+ data.tar.gz: a66d02c721925e4165e7632471f4549942aa3f9b
5
5
  SHA512:
6
- metadata.gz: 50795ef78b574be4a12b1714b532ffd4484d2c25f385550f1e77c4c80e4a7db0f623ba23405e1f298b5691419ea6f0975fc479f70f6bb8e5b72507fc069a24c2
7
- data.tar.gz: 61fff4e7a2e055a6e0e2674153e943da12a16b83145ee59452208cfa513110529b427dad7b0335213b573bae47911bcf7949131f0b4f5c89d5d5f167cb09269c
6
+ metadata.gz: b347c8599d3aa6cc5863fd754012a8d175bc5751e750fe11fb4313c1b5cf806b6950ce5785a1874a7dd5d322a1281b44dea7a76ffb4bab436b3140927f8b93fd
7
+ data.tar.gz: 1becef818b6ddb8174ed9e9e0c6f44eab02415b2f115a2bd4971ba7f53b68ddb928b98726501d8c1647399991acdad600a1f11e7b008cad0525ea2ef36b18065
@@ -2,62 +2,77 @@ module Apprank
2
2
  class App
3
3
 
4
4
  attr_accessor :name, :icon_urls, :summary, :price, :content_type, :rights, :title,
5
- :link, :itunes_url, :itunes_id, :bundle_id, :artist, :artist, :category, :release_date
5
+ :link, :preview, :itunes_url, :itunes_id, :bundle_id, :artist, :artist, :category, :release_date
6
6
 
7
7
  alias_method :developer, :artist
8
8
 
9
9
  def initialize(hash)
10
- @name = hash["im:name"]["label"]
11
- @icon_urls = {}
12
- hash["im:image"].each do |image|
13
- height =
14
- if image["attributes"]["height"] == '53'
15
- :small
16
- elsif image["attributes"]["height"] == '75'
17
- :medium
18
- else
19
- :large
20
- end
21
- @icon_urls[height] = image["label"]
22
- end
23
- @summary = hash["summary"]["label"]
10
+ @name = App.get_label(hash, "im:name")
11
+ @icon_urls = App.get_icon_urls(hash["im:image"])
12
+ @summary = App.get_label(hash, "summary")
13
+
24
14
  @price = {
25
- :amount => hash["im:price"]["attributes"]["amount"].to_f,
26
- :currency => hash["im:price"]["attributes"]["currency"]
15
+ amount: App.get_attributes(hash, "im:price")["amount"].to_f,
16
+ currency: App.get_attributes(hash, "im:price")["currency"],
27
17
  }
28
- @content_type = hash["rights"]["contentType"]
29
- @rights = hash["rights"]["label"]
30
- @title = hash["title"]["label"]
31
-
32
- link = hash["link"]
33
- if link["attributes"]["title"] == "Preview"
34
- @preview = link["attributes"]["href"]
35
- else
36
- @link = link["attributes"]["href"]
37
- end
18
+ @content_type = App.get_attributes(hash, "im:contentType")["term"]
19
+ @rights = App.get_label(hash, "rights")
20
+ @title = App.get_label(hash, "title")
21
+ @link = App.get_attributes(hash, "link")["href"]
38
22
 
39
- @itunes_url = hash["id"]["label"]
40
- @itunes_id = hash["id"]['attributes']['im:id']
41
- @bundle_id = hash["id"]['attributes']['im:bundleId']
23
+ @itunes_url = App.get_label(hash, "id")
24
+ @itunes_id = App.get_attributes(hash, "id")['im:id']
25
+ @bundle_id = App.get_attributes(hash, "id")['im:bundleId']
42
26
 
43
27
  @artist = {
44
- :name => hash["im:artist"]["label"],
45
- :url => hash["im:artist"]["attributes"]["href"]
28
+ :name => App.get_label(hash, "im:artist"),
29
+ :url => App.get_attributes(hash, "im:artist")["href"],
46
30
  }
31
+ category = App.get_attributes(hash, "category")
47
32
  @category = {
48
- :name => hash["category"]["attributes"]["term"],
49
- :url => hash["category"]["attributes"]["scheme"]
33
+ :name => category["term"],
34
+ :url => category["scheme"],
50
35
  }
51
- @release_date = Time.parse(hash["im:releaseDate"]["label"])
36
+ @release_date = Time.parse(App.get_label(hash, "im:releaseDate"))
52
37
  end
53
38
 
54
39
  def itunes_id
55
- self.itunes_url.split(/\//).last.split(/\?/).first.gsub(/[^\d]/,'')
40
+ self.itunes_url.split(/\//).last.split(/\?/).first.gsub(/[^\d]/, '')
41
+ end
42
+
43
+ def category_id
44
+ self.category[:url].split(/\//).last.split(/\?/).first.gsub(/[^\d]/, '')
56
45
  end
57
46
 
58
47
  def is_free?
59
48
  self.price[:amount].zero?
60
49
  end
61
50
 
51
+ private
52
+
53
+ def self.get_attributes(hash, field)
54
+ hash[field]["attributes"]
55
+ end
56
+
57
+ def self.get_label(hash, field)
58
+ hash[field]["label"]
59
+ end
60
+
61
+ def self.get_icon_urls(images)
62
+ icon_urls = {}
63
+ images.each do |image|
64
+ height =
65
+ if image["attributes"]["height"] == '53'
66
+ :small
67
+ elsif image["attributes"]["height"] == '75'
68
+ :medium
69
+ else
70
+ :large
71
+ end
72
+ icon_urls[height] = image["label"]
73
+ end
74
+ icon_urls
75
+ end
76
+
62
77
  end
63
78
  end
@@ -17,9 +17,10 @@ describe App do
17
17
  },
18
18
  summary: "Tap the ball carefully through each obstacle and your ball will switch color with some powerups.\nYou must follow the color pattern on each obstacle to cross it ! \n\nBe careful not to pass through the wrong color, or you’ll have to start again.",
19
19
  price: {
20
- amount: 0.0,
20
+ amount: 0.0,
21
21
  currency: "USD"
22
22
  },
23
+ content_type: "Application",
23
24
  rights: "© 2016 Fortafy Games",
24
25
  title: "Color Switch - Samuel Ratumaitavuki",
25
26
  link: "https://itunes.apple.com/us/app/color-switch/id1053533457?mt=8&uo=2",
@@ -32,7 +33,7 @@ describe App do
32
33
  },
33
34
  category: {
34
35
  name: "Games",
35
- url: "https://itunes.apple.com/us/genre/ios-games/id6014?mt=8&uo=2"
36
+ url: "https://itunes.apple.com/us/genre/ios-games/id6014?mt=8&uo=2"
36
37
  },
37
38
  }
38
39
 
@@ -40,6 +41,7 @@ describe App do
40
41
  expect(app.icon_urls).to eq(expected[:icon_urls])
41
42
  expect(app.summary).to eq(expected[:summary])
42
43
  expect(app.price).to eq(expected[:price])
44
+ expect(app.content_type).to eq(expected[:content_type])
43
45
  expect(app.rights).to eq(expected[:rights])
44
46
  expect(app.title).to eq(expected[:title])
45
47
  expect(app.link).to eq(expected[:link])
@@ -50,6 +52,9 @@ describe App do
50
52
  expect(app.category).to eq(expected[:category])
51
53
  expect(app.release_date).to be_a(Time)
52
54
 
55
+ expect(app.itunes_id).to eq("1053533457")
56
+ expect(app.category_id).to eq("6014")
57
+
53
58
 
54
59
  end
55
60
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apprank
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - hc5duke
@@ -28,7 +28,8 @@ files:
28
28
  - spec/spec.opts
29
29
  - spec/spec_helper.rb
30
30
  homepage: https://www.github.com/hc5duke/apprank
31
- licenses: []
31
+ licenses:
32
+ - MIT
32
33
  metadata: {}
33
34
  post_install_message:
34
35
  rdoc_options: []