hot_uk_deals 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/hot_uk_deals.rb +64 -0
- metadata +45 -0
data/lib/hot_uk_deals.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
class HotUKDeals
|
5
|
+
|
6
|
+
API_URI = 'http://api.hotukdeals.com/rest_api/v2/'
|
7
|
+
|
8
|
+
def self.developer_key
|
9
|
+
class_variable_defined?(:@@developer_key) ? @@developer_key : nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.developer_key=(developer_key)
|
13
|
+
@@developer_key = developer_key
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.results
|
17
|
+
class_variable_defined?(:@@results) ? @@results : nil
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.error
|
21
|
+
class_variable_defined?(:@@error) ? @@error : nil
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.send_request(parameters = {})
|
25
|
+
begin
|
26
|
+
@@developer_key = nil unless class_variable_defined?(:@@developer_key)
|
27
|
+
@@results = nil
|
28
|
+
@@error = nil
|
29
|
+
parameters.merge!(mandatory_parameters)
|
30
|
+
api_uri = URI(HotUKDeals::API_URI)
|
31
|
+
api_uri.query = URI.encode_www_form(parameters)
|
32
|
+
response = Net::HTTP.get(api_uri)
|
33
|
+
parse_response(response)
|
34
|
+
rescue
|
35
|
+
set_network_error
|
36
|
+
return false
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.mandatory_parameters
|
41
|
+
{
|
42
|
+
'key' => @@developer_key,
|
43
|
+
'output' => 'json'
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.parse_response(response)
|
48
|
+
begin
|
49
|
+
@@results = JSON.parse(response)
|
50
|
+
if @@error = @@results['error']
|
51
|
+
return false
|
52
|
+
end
|
53
|
+
rescue
|
54
|
+
set_network_error
|
55
|
+
return false
|
56
|
+
end
|
57
|
+
true
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.set_network_error
|
61
|
+
@@error = 'Network error'
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hot_uk_deals
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Christopher Patuzzo
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-12-27 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: A gem to be used for accessing the HotUKDeals API
|
15
|
+
email: chris.patuzzo@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/hot_uk_deals.rb
|
21
|
+
homepage: https://github.com/cpatuzzo/hot_uk_deals
|
22
|
+
licenses: []
|
23
|
+
post_install_message:
|
24
|
+
rdoc_options: []
|
25
|
+
require_paths:
|
26
|
+
- lib
|
27
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 1.8.10
|
42
|
+
signing_key:
|
43
|
+
specification_version: 3
|
44
|
+
summary: HotUKDeals API Access
|
45
|
+
test_files: []
|