hukd 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.version = Hukd::VERSION
8
8
  s.authors = ["Cube Websites"]
9
9
  s.email = ["messages@cubewebsites.com"]
10
- s.homepage = ""
10
+ s.homepage = "https://github.com/cubewebsites/hukd"
11
11
  s.summary = "API Wrapper for HotUKDeals (HUKD)"
12
12
  s.description = "API Wrapper for HotUKDeals (HUKD)"
13
13
 
@@ -100,18 +100,16 @@ module Hukd
100
100
  end
101
101
 
102
102
  # Make a request
103
- resp = HTTParty.get("#{API_BASE_URL}", :query => options)
103
+ resp = HTTParty.get("#{API_BASE_URL}", { :query => options, :headers =>{ 'ContentType' => 'application/json charset=utf-8' } })
104
104
 
105
105
  # Got a success response
106
106
  if resp.code == 200
107
- deals = MultiJson.load(resp.body)
108
107
  # Ensure a valid response is returned
109
- if (deals['error'])
110
- raise Exception, deals['error']
108
+ if (resp['error'])
109
+ raise Exception, resp['error']
111
110
  end
112
-
113
- # Returned parsed deals
114
- return parse_deals(deals)
111
+ # Returned parsed deals
112
+ return parse_deals(resp)
115
113
  end
116
114
 
117
115
  end
@@ -119,6 +117,7 @@ module Hukd
119
117
  def parse_deals(hash)
120
118
  dealsArray = Array.new
121
119
  hash["deals"]["items"].each do |deal|
120
+ deal.map { |k, v| deal[k] = v.is_a?(String) ? v.encode("iso-8859-1") : v }
122
121
  dealsArray.push(Deal.new(deal, self))
123
122
  end
124
123
  dealsArray
@@ -2,10 +2,12 @@ module Hukd
2
2
  class Deal
3
3
 
4
4
  attr_accessor :title, :deal_link, :mobile_deal_link, :deal_image, :description, :submit_time, :hot_time, :poster_name,
5
- :temperature, :price, :timestamp, :expired,
5
+ :temperature, :temperature_rounded, :price, :timestamp, :expired,
6
6
  :forum_name, :forum_url_name, :category_name, :category_url_name, :merchant_name, :merchant_url_name,
7
7
  :tags, :deal_image_highres
8
8
 
9
+ # @param [Hash] dealhash
10
+ # @param [Hukd] hukd
9
11
  def initialize(dealhash,hukd)
10
12
  @title = dealhash["title"]
11
13
  @deal_link = dealhash["deal_link"]
@@ -16,6 +18,7 @@ module Hukd
16
18
  @hot_time = dealhash["hot_time"]
17
19
  @poster_name = dealhash["poster_name"]
18
20
  @temperature = dealhash["temperature"]
21
+ @temperature_rounded = temperature.to_int
19
22
  @price = dealhash["price"]
20
23
  @timestamp = dealhash["timestamp"]
21
24
  @expired = dealhash["expired"]
@@ -39,5 +42,7 @@ module Hukd
39
42
  tags
40
43
  end
41
44
 
45
+
46
+
42
47
  end
43
48
  end
@@ -1,3 +1,3 @@
1
1
  module Hukd
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -0,0 +1,14 @@
1
+ require "rspec"
2
+ require "hukd"
3
+
4
+ describe Hukd::Deal do
5
+
6
+ before(:all) do
7
+ @deal = Hukd.new("API_KEY_HERE").hottest('deals','',1)[0]
8
+ end
9
+
10
+ it "should have a rounded temperature" do
11
+ @deal.temperature_rounded.should be_an_integer
12
+ end
13
+
14
+ end
@@ -8,45 +8,45 @@ describe Hukd::Base do
8
8
  end
9
9
 
10
10
  it "should get hottest deals" do
11
- Hukd.new("YOUR_API_KEY_HERE").hottest('deals').count.should equal(20)
11
+ Hukd.new("API_KEY_HERE").hottest('deals').count.should equal(20)
12
12
  end
13
13
 
14
14
  it "should get a custom number of deals" do
15
- Hukd.new("YOUR_API_KEY_HERE").hottest('deals','',10).count.should equal(10)
15
+ Hukd.new("API_KEY_HERE").hottest('deals','',10).count.should equal(10)
16
16
  end
17
17
 
18
18
  it "shouldn't get more than 500 deals" do
19
- Hukd.new("YOUR_API_KEY_HERE").hottest('deals','',10000).count.should equal(500)
19
+ Hukd.new("API_KEY_HERE").hottest('deals','',10000).count.should equal(500)
20
20
  end
21
21
 
22
22
  it "should be able to specify a forum" do
23
- Hukd.new("YOUR_API_KEY_HERE").hottest('vouchers','',1)[0].forum_url_name.should == "vouchers"
23
+ Hukd.new("API_KEY_HERE").hottest('vouchers','',1)[0].forum_url_name.should == "vouchers"
24
24
  end
25
25
 
26
26
  it "should be able to specify a category" do
27
- Hukd.new("YOUR_API_KEY_HERE").hottest('','fashion',0)[0].category_url_name.should == "fashion"
27
+ Hukd.new("API_KEY_HERE").hottest('','fashion',0)[0].category_url_name.should == "fashion"
28
28
  end
29
29
 
30
30
  it "should be able to specify a forum and category" do
31
- deal = Hukd.new("YOUR_API_KEY_HERE").hottest('freebies','mobiles',1)[0]
31
+ deal = Hukd.new("API_KEY_HERE").hottest('freebies','mobiles',1)[0]
32
32
  deal.forum_url_name.should == "freebies"
33
33
  deal.category_url_name.should == "mobiles"
34
34
  end
35
35
 
36
36
  it "should search by username" do
37
- Hukd.new("YOUR_API_KEY_HERE").user('wishihadadonkey','','',1)[0].poster_name.should == "wishihadadonkey"
37
+ Hukd.new("API_KEY_HERE").user('wishihadadonkey','','',1)[0].poster_name.should == "wishihadadonkey"
38
38
  end
39
39
 
40
40
  it "should search by tag" do
41
- deal = Hukd.new("YOUR_API_KEY_HERE").tag('xbox','deals','',1)[0].tags.should include('xbox')
41
+ Hukd.new("API_KEY_HERE").tag('xbox','deals','',1)[0].tags.should include('xbox')
42
42
  end
43
43
 
44
44
  it "should search by merchant" do
45
- Hukd.new("YOUR_API_KEY_HERE").merchant('itunes.apple.com','','',1)[0].merchant_url_name.should == "itunes.apple.com"
45
+ Hukd.new("API_KEY_HERE").merchant('itunes.apple.com','','',1)[0].merchant_url_name.should == "itunes.apple.com"
46
46
  end
47
47
 
48
48
  it "should search by keyword" do
49
- Hukd.new("YOUR_API_KEY_HERE").search('xbox','','',false,1,1)[0].title.should include("xbox")
49
+ Hukd.new("API_KEY_HERE").search('xbox','deals','',false,1,1)[0].title.downcase.should include("xbox")
50
50
  end
51
51
 
52
52
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hukd
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-05 00:00:00.000000000 Z
12
+ date: 2012-07-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &2157188460 !ruby/object:Gem::Requirement
16
+ requirement: &2153284900 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '2.6'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2157188460
24
+ version_requirements: *2153284900
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: httparty
27
- requirement: &2157188040 !ruby/object:Gem::Requirement
27
+ requirement: &2153283600 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2157188040
35
+ version_requirements: *2153283600
36
36
  description: API Wrapper for HotUKDeals (HUKD)
37
37
  email:
38
38
  - messages@cubewebsites.com
@@ -49,8 +49,9 @@ files:
49
49
  - lib/hukd/base.rb
50
50
  - lib/hukd/deal.rb
51
51
  - lib/hukd/version.rb
52
+ - spec/deal_spec.rb
52
53
  - spec/hukd_spec.rb
53
- homepage: ''
54
+ homepage: https://github.com/cubewebsites/hukd
54
55
  licenses: []
55
56
  post_install_message:
56
57
  rdoc_options: []
@@ -75,4 +76,5 @@ signing_key:
75
76
  specification_version: 3
76
77
  summary: API Wrapper for HotUKDeals (HUKD)
77
78
  test_files:
79
+ - spec/deal_spec.rb
78
80
  - spec/hukd_spec.rb