redflex-hydrogen-ruby 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +0 -0
- data/README.md +40 -0
- data/VERSION.yml +4 -0
- data/lib/hydrogen/base.rb +45 -0
- data/lib/hydrogen/request.rb +48 -0
- data/lib/hydrogen.rb +21 -0
- metadata +58 -0
data/History.txt
ADDED
File without changes
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
Hydrogen
|
2
|
+
========
|
3
|
+
|
4
|
+
This is a Hydrogen API Ruby client library.
|
5
|
+
|
6
|
+
|
7
|
+
## Requirements ##############################################################
|
8
|
+
|
9
|
+
* HTTParty
|
10
|
+
|
11
|
+
|
12
|
+
## Install ###################################################################
|
13
|
+
|
14
|
+
Easiest install is via RubyGems:
|
15
|
+
|
16
|
+
$ gem install hydrogen
|
17
|
+
|
18
|
+
or
|
19
|
+
|
20
|
+
$ gem sources -a http://gems.github.com/ (you only need to do this once)
|
21
|
+
$ gem install redflex-hydrogen-ruby
|
22
|
+
|
23
|
+
The gem from GitHub will generally by available sooner than the gem from
|
24
|
+
Rubyforge. Both sources will eventually contain the same releases.
|
25
|
+
|
26
|
+
|
27
|
+
## Source ####################################################################
|
28
|
+
|
29
|
+
Hydrogen's Git repo is available on GitHub, which can be browsed at:
|
30
|
+
|
31
|
+
http://github.com/redflex/hydrogen-ruby
|
32
|
+
|
33
|
+
and cloned with:
|
34
|
+
|
35
|
+
git clone git://github.com/redflex/hydrogen-ruby.git
|
36
|
+
|
37
|
+
|
38
|
+
## Usage #####################################################################
|
39
|
+
|
40
|
+
***TODO:** Usage docs*
|
data/VERSION.yml
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
module Hydrogen
|
2
|
+
class Base
|
3
|
+
|
4
|
+
|
5
|
+
#attr_reader :client
|
6
|
+
|
7
|
+
|
8
|
+
def initialize(account, username='', password='', options={})
|
9
|
+
@options = options
|
10
|
+
base_uri = "http#{'s' if options[:ssl]}://#{account}.hydrogenapp.com"
|
11
|
+
@request = Request.new({:base_uri => base_uri, :username => username, :password => password})
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
# Options: since_id, max_id, count, page, since
|
16
|
+
def topics(query={})
|
17
|
+
response = perform_get('/topics.json', :query => query)
|
18
|
+
response['topics']
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
def topic(id)
|
23
|
+
response = perform_get("/topics/#{id}.json")
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
def comments(topic_id)
|
28
|
+
response = perform_get("/topics/#{topic_id}/comments.json")
|
29
|
+
response['comments']
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
private
|
36
|
+
def perform_get(path, options={})
|
37
|
+
@request.perform_get("#{path}", options)
|
38
|
+
end
|
39
|
+
|
40
|
+
def perform_post(path, options={})
|
41
|
+
Request.perform_post(path, options)
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Hydrogen
|
2
|
+
class Request
|
3
|
+
|
4
|
+
|
5
|
+
def initialize(options={})
|
6
|
+
@options = {:mash => true}.merge(options)
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
def perform_get(path, query={})
|
11
|
+
response = HTTParty.get("#{@options[:base_uri]}#{path}", :query => query)
|
12
|
+
perform(response)
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
private
|
17
|
+
def perform(response)
|
18
|
+
data = parse(response)
|
19
|
+
@options[:mash] ? mash(data) : data
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
def parse(response)
|
24
|
+
Crack::JSON.parse(response.body)
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
def mash(obj)
|
29
|
+
if obj.is_a?(Array)
|
30
|
+
obj.map { |item| make_mash_with_consistent_hash(item) }
|
31
|
+
elsif obj.is_a?(Hash)
|
32
|
+
make_mash_with_consistent_hash(obj)
|
33
|
+
else
|
34
|
+
obj
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
def make_mash_with_consistent_hash(obj)
|
40
|
+
m = Mash.new(obj)
|
41
|
+
def m.hash
|
42
|
+
inspect.hash
|
43
|
+
end
|
44
|
+
return m
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
data/lib/hydrogen.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'httparty'
|
3
|
+
require 'mash'
|
4
|
+
|
5
|
+
|
6
|
+
module Hydrogen
|
7
|
+
class HydrogenError < StandardError
|
8
|
+
attr_reader :data
|
9
|
+
|
10
|
+
def initialize(data)
|
11
|
+
@data = data
|
12
|
+
super
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
directory = File.expand_path(File.dirname(__FILE__))
|
19
|
+
|
20
|
+
require File.join(directory, 'hydrogen', 'base')
|
21
|
+
require File.join(directory, 'hydrogen', 'request')
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: redflex-hydrogen-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matt Kirman
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-08-26 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: A Ruby implementation of the Hydrogen API.
|
17
|
+
email: contact@redflex.co.uk
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.md
|
24
|
+
files:
|
25
|
+
- History.txt
|
26
|
+
- README.md
|
27
|
+
- VERSION.yml
|
28
|
+
- lib/hydrogen.rb
|
29
|
+
- lib/hydrogen/base.rb
|
30
|
+
- lib/hydrogen/request.rb
|
31
|
+
has_rdoc: false
|
32
|
+
homepage: http://redflex.co.uk/products/hydrogen
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options:
|
35
|
+
- --charset=UTF-8
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: "0"
|
43
|
+
version:
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: "0"
|
49
|
+
version:
|
50
|
+
requirements: []
|
51
|
+
|
52
|
+
rubyforge_project: hydrogen
|
53
|
+
rubygems_version: 1.2.0
|
54
|
+
signing_key:
|
55
|
+
specification_version: 3
|
56
|
+
summary: A Ruby implementation of the Hydrogen API.
|
57
|
+
test_files: []
|
58
|
+
|