chrisjpowers-fat_num 0.1.1
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.
- data/LICENSE +21 -0
- data/README.rdoc +27 -0
- data/lib/fat_num.rb +55 -0
- metadata +64 -0
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Copyright (c) 2009 Chris Powers, The Killswitch Collective
|
|
2
|
+
http://killswitchcollective.com
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
5
|
+
a copy of this software and associated documentation files (the
|
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
10
|
+
the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be
|
|
13
|
+
included in all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
= FatNum
|
|
2
|
+
|
|
3
|
+
<em>Chris Powers</em>
|
|
4
|
+
|
|
5
|
+
The FatNum gem is a client for the simple API of http://www.fatnum.com.
|
|
6
|
+
|
|
7
|
+
== Getting Setup
|
|
8
|
+
|
|
9
|
+
First off, go to http://www.fatnum.com and sign up for an account. Create a new statistic and note the five-character token of your stat.
|
|
10
|
+
|
|
11
|
+
== Example
|
|
12
|
+
|
|
13
|
+
require 'rubygems'
|
|
14
|
+
require 'fat_num'
|
|
15
|
+
|
|
16
|
+
f = FatNum.new('your@email.com', 'password')
|
|
17
|
+
|
|
18
|
+
# get your statistic
|
|
19
|
+
response = f.get('e37gh')
|
|
20
|
+
response.digit #=> 120
|
|
21
|
+
response.description #=> 'batches left'
|
|
22
|
+
|
|
23
|
+
# update your statistic
|
|
24
|
+
f.update('e37gh', 119)
|
|
25
|
+
|
|
26
|
+
# sure enough, our update was successful
|
|
27
|
+
f.get('e37gh').digit #=> 119
|
data/lib/fat_num.rb
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Client class for accessing the FatNum API.
|
|
2
|
+
class FatNum
|
|
3
|
+
require 'rubygems'
|
|
4
|
+
require 'net/http'
|
|
5
|
+
require 'uri'
|
|
6
|
+
require 'hpricot'
|
|
7
|
+
|
|
8
|
+
class AuthenticationError < Exception; end
|
|
9
|
+
class ParsingError < Exception; end
|
|
10
|
+
|
|
11
|
+
FATNUM_HOST = 'www.fatnum.com'
|
|
12
|
+
FATNUM_PORT = 80
|
|
13
|
+
|
|
14
|
+
# Email and password are only required for updating a FatNum
|
|
15
|
+
def initialize(email=nil, pword=nil)
|
|
16
|
+
@email = email
|
|
17
|
+
@pword = pword
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Retrieves the FatNum associated with the given token as an integer
|
|
21
|
+
def get(token)
|
|
22
|
+
Net::HTTP.start(FATNUM_HOST, FATNUM_PORT) {|http|
|
|
23
|
+
req = Net::HTTP::Get.new("/statistics/#{token}.xml")
|
|
24
|
+
response = http.request(req)
|
|
25
|
+
return Response.new(response)
|
|
26
|
+
}
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Updates the FatNum associated with the given token
|
|
30
|
+
def update(token, value)
|
|
31
|
+
raise AuthenticationError, "Cannot update FatNum without an email address." unless @email
|
|
32
|
+
raise AuthenticationError, "Cannot update FatNum without a password." unless @pword
|
|
33
|
+
|
|
34
|
+
Net::HTTP.start(FATNUM_HOST, FATNUM_PORT) {|http|
|
|
35
|
+
req = Net::HTTP::Post.new("/statistics/#{token}.xml")
|
|
36
|
+
req.basic_auth @email, @pword
|
|
37
|
+
response = http.request(req, "_method=put&statistic[digit]=#{URI.encode(value.to_s)}")
|
|
38
|
+
return response.body
|
|
39
|
+
}
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Object returned by the #get method
|
|
43
|
+
class Response
|
|
44
|
+
attr_reader :digit, :description
|
|
45
|
+
def initialize(response)
|
|
46
|
+
xml = Hpricot.parse(response.body)
|
|
47
|
+
dig = xml.search("digit").first
|
|
48
|
+
des = xml.search("description").first
|
|
49
|
+
raise ParsingError, "Unable to parse XML" unless dig && des
|
|
50
|
+
@digit = dig.innerText.to_i
|
|
51
|
+
@description = des.innerText
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: chrisjpowers-fat_num
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Chris Powers
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2009-03-13 00:00:00 -07:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies:
|
|
15
|
+
- !ruby/object:Gem::Dependency
|
|
16
|
+
name: hpricot
|
|
17
|
+
type: :runtime
|
|
18
|
+
version_requirement:
|
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
20
|
+
requirements:
|
|
21
|
+
- - ">="
|
|
22
|
+
- !ruby/object:Gem::Version
|
|
23
|
+
version: "0.6"
|
|
24
|
+
version:
|
|
25
|
+
description:
|
|
26
|
+
email: chrisjpowers@gmail.com
|
|
27
|
+
executables: []
|
|
28
|
+
|
|
29
|
+
extensions: []
|
|
30
|
+
|
|
31
|
+
extra_rdoc_files: []
|
|
32
|
+
|
|
33
|
+
files:
|
|
34
|
+
- README.rdoc
|
|
35
|
+
- LICENSE
|
|
36
|
+
- lib/fat_num.rb
|
|
37
|
+
has_rdoc: true
|
|
38
|
+
homepage: http://www.fatnum.com
|
|
39
|
+
post_install_message:
|
|
40
|
+
rdoc_options: []
|
|
41
|
+
|
|
42
|
+
require_paths:
|
|
43
|
+
- lib
|
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
45
|
+
requirements:
|
|
46
|
+
- - ">="
|
|
47
|
+
- !ruby/object:Gem::Version
|
|
48
|
+
version: "0"
|
|
49
|
+
version:
|
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: "0"
|
|
55
|
+
version:
|
|
56
|
+
requirements: []
|
|
57
|
+
|
|
58
|
+
rubyforge_project:
|
|
59
|
+
rubygems_version: 1.2.0
|
|
60
|
+
signing_key:
|
|
61
|
+
specification_version: 2
|
|
62
|
+
summary: The FlexibleCsv gem uses the FasterCSV gem to parse user created CSV files that may not have standard headers.
|
|
63
|
+
test_files: []
|
|
64
|
+
|