redflex-hydrogen-ruby 0.1.1 → 0.9.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.
data/README.md CHANGED
@@ -1,12 +1,14 @@
1
1
  Hydrogen
2
2
  ========
3
3
 
4
- This is a Hydrogen API Ruby client library.
4
+ This is a Hydrogen API Ruby client library. As the Hydrogen API is updated
5
+ there will be a simultaneous update of this library.
5
6
 
6
7
 
7
8
  ## Requirements ##############################################################
8
9
 
9
10
  * HTTParty
11
+ * Mash
10
12
 
11
13
 
12
14
  ## Install ###################################################################
@@ -37,4 +39,42 @@ and cloned with:
37
39
 
38
40
  ## Usage #####################################################################
39
41
 
40
- ***TODO:** Usage docs*
42
+ Hydrogen-ruby gives you object model access to the Hydrogen API. Once you have
43
+ created a `client` object, you can traverse it to find topics and comments.
44
+
45
+
46
+ ### Initialize a Client Object ###############################################
47
+
48
+ The first step is to create a `Hydrogen::Base` object to represent your
49
+ client.
50
+
51
+ require 'hydrogen'
52
+ client = Hydrogen::Base.new('redflex')
53
+
54
+ In the above example, the Hydrogen account is `redflex` (this is the same as
55
+ *account*.hydrogenapp.com, **not** your user name).
56
+
57
+
58
+ ### Getting a list of topics #################################################
59
+
60
+ From the `Base` object you can get a list of topics as an array. This defaults
61
+ to the last 15 topics to be created, as specified in the Hydrogen API.
62
+
63
+ client.topics.each { |topic| puts topic.inspect }
64
+
65
+ You can also pass any Hydrogen API parameters to this method, for example:
66
+
67
+ client.topics({ :page => 1 }).each { |topic| puts topic.inspect }
68
+
69
+ You can also get a single topic. *Note: this method is `topic` and **not**
70
+ `topics`*.
71
+
72
+ client.topic( topic_id ).inspect
73
+
74
+
75
+ ### Getting a list of comments ###############################################
76
+
77
+ You can also get a list of comments from the `Base` object. You will, of
78
+ course, need to know the `topic_id`.
79
+
80
+ client.comments( topic_id ).each { |comment| puts comment.inspect }
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
- :minor: 1
4
- :patch: 1
3
+ :minor: 9
4
+ :patch: 0
@@ -2,9 +2,6 @@ module Hydrogen
2
2
  class Base
3
3
 
4
4
 
5
- #attr_reader :client
6
-
7
-
8
5
  def initialize(account, username='', password='', options={})
9
6
  @options = options
10
7
  base_uri = "http#{'s' if options[:ssl]}://#{account}.hydrogenapp.com"
@@ -14,31 +11,55 @@ module Hydrogen
14
11
 
15
12
  # Options: since_id, max_id, count, page, since
16
13
  def topics(query={})
17
- response = perform_get('/topics.json', :query => query)
14
+ response = perform_get("/topics.json", query)
18
15
  response['topics']
19
16
  end
20
17
 
21
18
 
19
+ # Options:
22
20
  def topic(id)
23
21
  response = perform_get("/topics/#{id}.json")
24
22
  end
25
23
 
26
24
 
27
- def comments(topic_id)
28
- response = perform_get("/topics/#{topic_id}/comments.json")
25
+ # Options:
26
+ def create_topic(query={})
27
+ response = perform_post("/topics/create.json", query)
28
+ end
29
+
30
+
31
+ # Options:
32
+ def delete_topic(id)
33
+ response = perform_get("/topics/#{id}/delete.json")
34
+ end
35
+
36
+
37
+ # Options:
38
+ def comments(topic_id, query={})
39
+ response = perform_get("/topics/#{topic_id}/comments.json", query)
29
40
  response['comments']
30
41
  end
31
42
 
32
43
 
44
+ # Options:
45
+ def comment(topic_id, comment_id)
46
+ response = perform_get("/topics/#{topic_id}/comments/#{comment_id}.json")
47
+ end
48
+
49
+
50
+ # Options: comment*, reply_to
51
+ def create_comment(topic_id, query={})
52
+ response = perform_post("/topics/#{topic_id}/comments/create.json", query)
53
+ end
33
54
 
34
55
 
35
56
  private
36
57
  def perform_get(path, options={})
37
- @request.perform_get("#{path}", options)
58
+ @request.perform_get(path, options)
38
59
  end
39
60
 
40
61
  def perform_post(path, options={})
41
- Request.perform_post(path, options)
62
+ @request.perform_post(path, options)
42
63
  end
43
64
 
44
65
  end
@@ -2,13 +2,23 @@ module Hydrogen
2
2
  class Request
3
3
 
4
4
 
5
+ include HTTParty
6
+
7
+
5
8
  def initialize(options={})
6
9
  @options = {:mash => true}.merge(options)
10
+ @auth = {:username => @options[:username], :password => @options[:password]} if @options[:username]
7
11
  end
8
12
 
9
13
 
10
14
  def perform_get(path, query={})
11
- response = HTTParty.get("#{@options[:base_uri]}#{path}", :query => query)
15
+ response = self.class.get("#{@options[:base_uri]}#{path}", { :query => query, :basic_auth => @auth })
16
+ perform(response)
17
+ end
18
+
19
+
20
+ def perform_post(path, query={})
21
+ response = self.class.post("#{@options[:base_uri]}#{path}", { :query => query, :basic_auth => @auth })
12
22
  perform(response)
13
23
  end
14
24
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redflex-hydrogen-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Kirman