hukd 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/Gemfile +4 -0
- data/README.md +90 -0
- data/Rakefile +1 -0
- data/hukd.gemspec +23 -0
- data/lib/hukd.rb +11 -0
- data/lib/hukd/base.rb +128 -0
- data/lib/hukd/deal.rb +43 -0
- data/lib/hukd/version.rb +3 -0
- data/spec/hukd_spec.rb +52 -0
- metadata +78 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
API Client for HotUKDeals (HUKD)
|
2
|
+
===================================
|
3
|
+
|
4
|
+
This client allows you to access all the documented API features from *HUKD REST API 2.0*
|
5
|
+
http://www.hotukdeals.com/rest-api/docs
|
6
|
+
|
7
|
+
Please note that the HUKD API Documentation is not entirely upto date (for example there is no longer a clothing category) and the deals return some additional fields such as mobile_deal_link which I've attempted to include.
|
8
|
+
You could say that the gem is actually more up to date than the API docs at the time of release :)
|
9
|
+
|
10
|
+
Prerequisites
|
11
|
+
-------------
|
12
|
+
|
13
|
+
gem install hukd
|
14
|
+
|
15
|
+
YOU ARE NOW READY TO GET SOME SWEET DEAL DATA!
|
16
|
+
|
17
|
+
Usage
|
18
|
+
-----
|
19
|
+
|
20
|
+
You can start of by creating an instance of the client, which just needs an Api Key.
|
21
|
+
|
22
|
+
require 'hukd'
|
23
|
+
hukd = Hukd.new("YOUR_API_KEY_HERE")
|
24
|
+
|
25
|
+
You can then make an API request to receive an array of Deal objects.
|
26
|
+
|
27
|
+
deals = hukd.hottest('deals')
|
28
|
+
|
29
|
+
The following API calls are available
|
30
|
+
|
31
|
+
hottest(forum='', category='', limit=20, options={})
|
32
|
+
newest(forum='', category='', limit=20, options={})
|
33
|
+
discussed(forum='', category='', limit=20, options={})
|
34
|
+
user(user='',forum='', category='', limit=20, options={})
|
35
|
+
tag(tag='',forum='', category='', limit=20, options={})
|
36
|
+
merchant(merchant='',forum='', category='', limit=20, options={})
|
37
|
+
online(forum='', category='', limit=20, options={})
|
38
|
+
offline(forum='', category='', limit=20, options={})
|
39
|
+
search(keywords='',forum='', category='', online=false, page=1, limit=20, exclude_expired=0)
|
40
|
+
|
41
|
+
The options hash can contain all the keys available from
|
42
|
+
http://www.hotukdeals.com/rest-api/docs
|
43
|
+
|
44
|
+
Each deal object has the following attributes available:
|
45
|
+
|
46
|
+
title
|
47
|
+
deal_link
|
48
|
+
mobile_deal_link
|
49
|
+
deal_image
|
50
|
+
description
|
51
|
+
submit_time
|
52
|
+
hot_time
|
53
|
+
poster_name
|
54
|
+
temperature
|
55
|
+
price
|
56
|
+
timestamp
|
57
|
+
expired
|
58
|
+
forum_name
|
59
|
+
forum_url_name
|
60
|
+
category_name
|
61
|
+
category_url_name
|
62
|
+
merchant_name
|
63
|
+
merchant_url_name
|
64
|
+
tags (a hash containing each tag as a string)
|
65
|
+
deal_image_highres
|
66
|
+
|
67
|
+
Combining everything together will give you something like this:
|
68
|
+
|
69
|
+
require 'hukd'
|
70
|
+
hukd = Hukd.new("YOUR_API_KEY_HERE")
|
71
|
+
deals = hukd.hottest('deals')
|
72
|
+
deals.each |deal| do
|
73
|
+
puts(deal.title)
|
74
|
+
end
|
75
|
+
|
76
|
+
This will fetch the hottest deals (default at 20) and print the title to the console.
|
77
|
+
|
78
|
+
Support
|
79
|
+
--------
|
80
|
+
|
81
|
+
Feel free to contact me or open an issue if need be.
|
82
|
+
|
83
|
+
PLEASE NOTE: You will need to add replace the "API_KEY_HERE" text with your key to make the tests pass.
|
84
|
+
|
85
|
+
Thanks
|
86
|
+
------
|
87
|
+
|
88
|
+
To the [great guide](https://github.com/radar/guides/blob/master/gem-development.md) by [Hrvoje Šimić](https://github.com/shime) to help me develop my first gem :)
|
89
|
+
|
90
|
+
To the [badfruit](https://github.com/brianmichel/BadFruit) gem by [brianmichel](https://github.com/brianmichel) which I referenced and to develop my own gem
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/hukd.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "hukd/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "hukd"
|
7
|
+
s.version = Hukd::VERSION
|
8
|
+
s.authors = ["Cube Websites"]
|
9
|
+
s.email = ["messages@cubewebsites.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = "API Wrapper for HotUKDeals (HUKD)"
|
12
|
+
s.description = "API Wrapper for HotUKDeals (HUKD)"
|
13
|
+
|
14
|
+
s.rubyforge_project = "hukd"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_development_dependency "rspec", "~> 2.6"
|
22
|
+
s.add_runtime_dependency "httparty"
|
23
|
+
end
|
data/lib/hukd.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "hukd/version"
|
2
|
+
require "httparty"
|
3
|
+
|
4
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), 'hukd', 'base')
|
5
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), 'hukd', 'deal')
|
6
|
+
|
7
|
+
module Hukd
|
8
|
+
def self.new(apikey)
|
9
|
+
Hukd::Base.new(apikey);
|
10
|
+
end
|
11
|
+
end
|
data/lib/hukd/base.rb
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
module Hukd
|
2
|
+
class Base
|
3
|
+
attr_accessor :api_key
|
4
|
+
API_VERSION = "2.0"
|
5
|
+
API_BASE_URL = "http://api.hotukdeals.com/rest_api/v2/"
|
6
|
+
|
7
|
+
def initialize(key)
|
8
|
+
@api_key = key
|
9
|
+
end
|
10
|
+
|
11
|
+
def hottest(forum='', category='', limit=20, options={})
|
12
|
+
options['order'] = 'hot'
|
13
|
+
get(forum, category, limit, options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def newest(forum='', category='', limit=20, options={})
|
17
|
+
options['order'] = 'new'
|
18
|
+
get(forum, category, limit, options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def discussed(forum='', category='', limit=20, options={})
|
22
|
+
options['order'] = 'discussed'
|
23
|
+
get(forum, category, limit, options)
|
24
|
+
end
|
25
|
+
|
26
|
+
def user(user='',forum='', category='', limit=20, options={})
|
27
|
+
if(options['order'].nil?)
|
28
|
+
options['order'] = 'new'
|
29
|
+
end
|
30
|
+
options['username'] = user
|
31
|
+
get(forum, category, limit, options)
|
32
|
+
end
|
33
|
+
|
34
|
+
def tag(tag='',forum='', category='', limit=20, options={})
|
35
|
+
if(options['order'].nil?)
|
36
|
+
options['order'] = 'new'
|
37
|
+
end
|
38
|
+
options['tag'] = tag
|
39
|
+
get(forum, category, limit, options)
|
40
|
+
end
|
41
|
+
|
42
|
+
def merchant(merchant='',forum='', category='', limit=20, options={})
|
43
|
+
if(options['order'].nil?)
|
44
|
+
options['order'] = 'new'
|
45
|
+
end
|
46
|
+
options['merchant'] = merchant
|
47
|
+
get(forum, category, limit, options)
|
48
|
+
end
|
49
|
+
|
50
|
+
def online(forum='', category='', limit=20, options={})
|
51
|
+
if(options['order'].nil?)
|
52
|
+
options['order'] = 'new'
|
53
|
+
end
|
54
|
+
options['online_offline'] = 'online'
|
55
|
+
get(forum, category, limit, options)
|
56
|
+
end
|
57
|
+
|
58
|
+
def offline(forum='', category='', limit=20, options={})
|
59
|
+
if(options['order'].nil?)
|
60
|
+
options['order'] = 'new'
|
61
|
+
end
|
62
|
+
options['online_offline'] = 'offline'
|
63
|
+
get(forum, category, limit, options)
|
64
|
+
end
|
65
|
+
|
66
|
+
def search(keywords='',forum='', category='', online=false, page=1, limit=20, exclude_expired=0)
|
67
|
+
options = {}
|
68
|
+
options['search'] = keywords
|
69
|
+
options['page'] = page.to_int
|
70
|
+
options['results_per_page'] = limit.to_int
|
71
|
+
if(online!=false)
|
72
|
+
options['online_offline'] = 'online'
|
73
|
+
end
|
74
|
+
|
75
|
+
if(exclude_expired!=0)
|
76
|
+
options['exclude_expired'] = true
|
77
|
+
end
|
78
|
+
get(forum,category,limit,options)
|
79
|
+
end
|
80
|
+
|
81
|
+
def get(forum='', category='', limit=20, options={})
|
82
|
+
# Set the API_KEY
|
83
|
+
options['key'] = @api_key
|
84
|
+
options['output'] = 'json'
|
85
|
+
|
86
|
+
# Set the limit as long as it doesn't exceed the maximum allowed
|
87
|
+
if(limit > 500)
|
88
|
+
limit = 500
|
89
|
+
end
|
90
|
+
options['results_per_page'] = limit
|
91
|
+
|
92
|
+
# Specify a forum
|
93
|
+
if(forum != '')
|
94
|
+
options['forum'] = forum
|
95
|
+
end
|
96
|
+
|
97
|
+
# Specify a category
|
98
|
+
if(category != '')
|
99
|
+
options['category'] = category
|
100
|
+
end
|
101
|
+
|
102
|
+
# Make a request
|
103
|
+
resp = HTTParty.get("#{API_BASE_URL}", :query => options)
|
104
|
+
|
105
|
+
# Got a success response
|
106
|
+
if resp.code == 200
|
107
|
+
deals = MultiJson.load(resp.body)
|
108
|
+
# Ensure a valid response is returned
|
109
|
+
if (deals['error'])
|
110
|
+
raise Exception, deals['error']
|
111
|
+
end
|
112
|
+
|
113
|
+
# Returned parsed deals
|
114
|
+
return parse_deals(deals)
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
def parse_deals(hash)
|
120
|
+
dealsArray = Array.new
|
121
|
+
hash["deals"]["items"].each do |deal|
|
122
|
+
dealsArray.push(Deal.new(deal, self))
|
123
|
+
end
|
124
|
+
dealsArray
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
end
|
data/lib/hukd/deal.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
module Hukd
|
2
|
+
class Deal
|
3
|
+
|
4
|
+
attr_accessor :title, :deal_link, :mobile_deal_link, :deal_image, :description, :submit_time, :hot_time, :poster_name,
|
5
|
+
:temperature, :price, :timestamp, :expired,
|
6
|
+
:forum_name, :forum_url_name, :category_name, :category_url_name, :merchant_name, :merchant_url_name,
|
7
|
+
:tags, :deal_image_highres
|
8
|
+
|
9
|
+
def initialize(dealhash,hukd)
|
10
|
+
@title = dealhash["title"]
|
11
|
+
@deal_link = dealhash["deal_link"]
|
12
|
+
@mobile_deal_link = dealhash["mobile_deal_link"]
|
13
|
+
@deal_image = dealhash["deal_image"]
|
14
|
+
@description = dealhash["description"]
|
15
|
+
@submit_time = dealhash["submit_time"]
|
16
|
+
@hot_time = dealhash["hot_time"]
|
17
|
+
@poster_name = dealhash["poster_name"]
|
18
|
+
@temperature = dealhash["temperature"]
|
19
|
+
@price = dealhash["price"]
|
20
|
+
@timestamp = dealhash["timestamp"]
|
21
|
+
@expired = dealhash["expired"]
|
22
|
+
@forum_name = dealhash["forum"]["name"]
|
23
|
+
@forum_url_name = dealhash["forum"]["url_name"]
|
24
|
+
@category_name = dealhash["category"]["name"]
|
25
|
+
@category_url_name = dealhash["category"]["url_name"]
|
26
|
+
@merchant_name = dealhash["merchant"]["name"]
|
27
|
+
@merchant_url_name = dealhash["merchant"]["url_name"]
|
28
|
+
@tags = parse_tags(dealhash["tags"])
|
29
|
+
@deal_image_highres = dealhash["deal_image_highres"]
|
30
|
+
@hukd = hukd
|
31
|
+
self
|
32
|
+
end
|
33
|
+
|
34
|
+
def parse_tags(hash)
|
35
|
+
tags = Array.new
|
36
|
+
hash["items"].each do |tag|
|
37
|
+
tags.push(tag['name'])
|
38
|
+
end
|
39
|
+
tags
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
data/lib/hukd/version.rb
ADDED
data/spec/hukd_spec.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require "rspec"
|
2
|
+
require "hukd"
|
3
|
+
|
4
|
+
describe Hukd::Base do
|
5
|
+
|
6
|
+
it "shouldn't work without an API key'" do
|
7
|
+
expect { Hukd.new("").hottest('deals') }.to raise_error
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should get hottest deals" do
|
11
|
+
Hukd.new("YOUR_API_KEY_HERE").hottest('deals').count.should equal(20)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should get a custom number of deals" do
|
15
|
+
Hukd.new("YOUR_API_KEY_HERE").hottest('deals','',10).count.should equal(10)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "shouldn't get more than 500 deals" do
|
19
|
+
Hukd.new("YOUR_API_KEY_HERE").hottest('deals','',10000).count.should equal(500)
|
20
|
+
end
|
21
|
+
|
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"
|
24
|
+
end
|
25
|
+
|
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"
|
28
|
+
end
|
29
|
+
|
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]
|
32
|
+
deal.forum_url_name.should == "freebies"
|
33
|
+
deal.category_url_name.should == "mobiles"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should search by username" do
|
37
|
+
Hukd.new("YOUR_API_KEY_HERE").user('wishihadadonkey','','',1)[0].poster_name.should == "wishihadadonkey"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should search by tag" do
|
41
|
+
deal = Hukd.new("YOUR_API_KEY_HERE").tag('xbox','deals','',1)[0].tags.should include('xbox')
|
42
|
+
end
|
43
|
+
|
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"
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should search by keyword" do
|
49
|
+
Hukd.new("YOUR_API_KEY_HERE").search('xbox','','',false,1,1)[0].title.should include("xbox")
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hukd
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Cube Websites
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-05 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &2157188460 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2.6'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2157188460
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: httparty
|
27
|
+
requirement: &2157188040 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2157188040
|
36
|
+
description: API Wrapper for HotUKDeals (HUKD)
|
37
|
+
email:
|
38
|
+
- messages@cubewebsites.com
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- Gemfile
|
45
|
+
- README.md
|
46
|
+
- Rakefile
|
47
|
+
- hukd.gemspec
|
48
|
+
- lib/hukd.rb
|
49
|
+
- lib/hukd/base.rb
|
50
|
+
- lib/hukd/deal.rb
|
51
|
+
- lib/hukd/version.rb
|
52
|
+
- spec/hukd_spec.rb
|
53
|
+
homepage: ''
|
54
|
+
licenses: []
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubyforge_project: hukd
|
73
|
+
rubygems_version: 1.8.15
|
74
|
+
signing_key:
|
75
|
+
specification_version: 3
|
76
|
+
summary: API Wrapper for HotUKDeals (HUKD)
|
77
|
+
test_files:
|
78
|
+
- spec/hukd_spec.rb
|