sitegraph 1.0.1 → 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.
- checksums.yaml +4 -4
- data/lib/sitegraph.rb +94 -12
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: be57cf3bd72a71dd7617bacb88ceea7bb9909218
|
|
4
|
+
data.tar.gz: 7cc81e998aa1ccaa15cdced2c6245e1b66b41766
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: befad266b9a440033fac96f28d6a3b49abc7a9b08a45c206983ac666d0dac7a0e7d4c51129496fc15b025722a0a1937198755fd0f8b8c5727249db9f8ae87f77
|
|
7
|
+
data.tar.gz: 231a2725c45e078975f2814e86a73c35b6bc2006c605a32f8d6404d6c6179c0e29a0bc139099f8330e97858563a79c1eef473bc0b7d470747e602b40465447de
|
data/lib/sitegraph.rb
CHANGED
|
@@ -1,19 +1,101 @@
|
|
|
1
|
+
require 'net/http'
|
|
2
|
+
require 'openssl'
|
|
3
|
+
require 'JSON'
|
|
4
|
+
|
|
5
|
+
API_SERVER = "https://sitegraph.net/api/"
|
|
6
|
+
API_VERSION = "1.0.0"
|
|
7
|
+
API_INFORMATION = "Ruby " + API_VERSION
|
|
8
|
+
|
|
1
9
|
class Sitegraph
|
|
2
|
-
|
|
3
|
-
def
|
|
4
|
-
|
|
10
|
+
attr_accessor :api_key
|
|
11
|
+
def initialize(api_key)
|
|
12
|
+
@api_key = api_key
|
|
5
13
|
end
|
|
6
|
-
|
|
7
|
-
|
|
14
|
+
# Increments a given statistic by the amount specified
|
|
15
|
+
#
|
|
16
|
+
# * *Args* :
|
|
17
|
+
# - +identifier+ -> The statistic's identifier, set when you created the statistic
|
|
18
|
+
# - +amount+ -> An integer specifying the amount by which to increment the statistic
|
|
19
|
+
# * *Returns* :
|
|
20
|
+
# - True if the statistic was incremented.
|
|
21
|
+
# * *Raises* :
|
|
22
|
+
# - +RuntimeException+ -> If there is a problem with your request, a RuntimeException will be raised with the
|
|
23
|
+
# information
|
|
24
|
+
#
|
|
25
|
+
def increment(identifier, amount)
|
|
26
|
+
response = self.post_request('increment',{
|
|
27
|
+
'authKey' => self.api_key,
|
|
28
|
+
'statistic' => identifier,
|
|
29
|
+
'amount' => amount,
|
|
30
|
+
'api_info' => API_INFORMATION
|
|
31
|
+
})
|
|
32
|
+
return True
|
|
8
33
|
end
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
34
|
+
# Decrements a given statistic by the amount specified
|
|
35
|
+
#
|
|
36
|
+
# * *Args* :
|
|
37
|
+
# - +identifier+ -> The statistic's identifier, set when you created the statistic
|
|
38
|
+
# - +amount+ -> An integer specifying the amount by which to decrease the statistic
|
|
39
|
+
# * *Returns* :
|
|
40
|
+
# - True if the statistic was decremented.
|
|
41
|
+
# * *Raises* :
|
|
42
|
+
# - +RuntimeException+ -> If there is a problem with your request, a RuntimeException will be raised with the
|
|
43
|
+
# information
|
|
44
|
+
#
|
|
45
|
+
def decrement(identifier, amount)
|
|
46
|
+
response = self.post_request('decrement',{
|
|
47
|
+
'authKey' => self.api_key,
|
|
48
|
+
'statistic' => identifier,
|
|
49
|
+
'amount' => amount,
|
|
50
|
+
'api_info' => API_INFORMATION
|
|
51
|
+
})
|
|
52
|
+
return True
|
|
53
|
+
end
|
|
54
|
+
# Creates a new event associated with your account in the Sitegraph system
|
|
55
|
+
#
|
|
56
|
+
# * *Args* :
|
|
57
|
+
# - +description+ -> A description of the event, such as "Launched v2.0"
|
|
58
|
+
# * *Returns* :
|
|
59
|
+
# - The event's unique identifier
|
|
60
|
+
# * *Raises* :
|
|
61
|
+
# - +RuntimeException+ -> If there is a problem with your request, a RuntimeException will be raised with the
|
|
62
|
+
# information
|
|
63
|
+
#
|
|
64
|
+
def create_event(description)
|
|
65
|
+
response = self.post_request('event',{
|
|
66
|
+
'authKey' => self.api_key,
|
|
67
|
+
'event' => description
|
|
68
|
+
})
|
|
69
|
+
return response[description]
|
|
12
70
|
end
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
71
|
+
# Helper function for POSTing to a Sitegraph URL
|
|
72
|
+
#
|
|
73
|
+
# * *Args* :
|
|
74
|
+
# - +url+ -> The URL to post to, without the trailing slash.
|
|
75
|
+
# - +data+ -> A hash of the data to post
|
|
76
|
+
# * *Returns* :
|
|
77
|
+
# - A hash of the parsed JSON response
|
|
78
|
+
# * *Raises* :
|
|
79
|
+
# - +RuntimeException+ -> If there is a problem with your request, a RuntimeException will be raised with the
|
|
80
|
+
# information
|
|
81
|
+
#
|
|
82
|
+
def post_request(url, data)
|
|
83
|
+
uri = URI.parse(API_SERVER + url + "/")
|
|
84
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
85
|
+
http.use_ssl = true
|
|
86
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
87
|
+
request = Net::HTTP::Post.new(uri.path)
|
|
88
|
+
request.body = URI.encode_www_form(data)
|
|
89
|
+
|
|
90
|
+
response = http.request(request)
|
|
91
|
+
|
|
92
|
+
json = JSON.parse(response.body)
|
|
93
|
+
|
|
94
|
+
error = json['error']
|
|
95
|
+
if error != nil
|
|
96
|
+
raise error
|
|
97
|
+
end
|
|
16
98
|
|
|
99
|
+
return json
|
|
17
100
|
end
|
|
18
|
-
|
|
19
101
|
end
|