redflex-hydrogen-ruby 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -7,7 +7,7 @@ there will be a simultaneous update of this library.
7
7
 
8
8
  ## Requirements ##############################################################
9
9
 
10
- * HTTParty
10
+ * Crack
11
11
  * Mash
12
12
 
13
13
 
@@ -49,10 +49,7 @@ The first step is to create a `Hydrogen::Base` object to represent your
49
49
  client.
50
50
 
51
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).
52
+ client = Hydrogen::Base.new('account_name', 'username', 'password')
56
53
 
57
54
 
58
55
  ### Getting a list of topics #################################################
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
+ :patch: 1
2
3
  :major: 0
3
4
  :minor: 9
4
- :patch: 0
data/lib/hydrogen/base.rb CHANGED
@@ -19,12 +19,14 @@ module Hydrogen
19
19
  # Options:
20
20
  def topic(id)
21
21
  response = perform_get("/topics/#{id}.json")
22
+ response['topic']
22
23
  end
23
24
 
24
25
 
25
26
  # Options:
26
27
  def create_topic(query={})
27
28
  response = perform_post("/topics/create.json", query)
29
+ response['topic']
28
30
  end
29
31
 
30
32
 
@@ -44,12 +46,14 @@ module Hydrogen
44
46
  # Options:
45
47
  def comment(topic_id, comment_id)
46
48
  response = perform_get("/topics/#{topic_id}/comments/#{comment_id}.json")
49
+ response['comment']
47
50
  end
48
51
 
49
52
 
50
53
  # Options: comment*, reply_to
51
54
  def create_comment(topic_id, query={})
52
55
  response = perform_post("/topics/#{topic_id}/comments/create.json", query)
56
+ response['comment']
53
57
  end
54
58
 
55
59
 
@@ -2,9 +2,6 @@ module Hydrogen
2
2
  class Request
3
3
 
4
4
 
5
- include HTTParty
6
-
7
-
8
5
  def initialize(options={})
9
6
  @options = {:mash => true}.merge(options)
10
7
  @auth = {:username => @options[:username], :password => @options[:password]} if @options[:username]
@@ -12,14 +9,25 @@ module Hydrogen
12
9
 
13
10
 
14
11
  def perform_get(path, query={})
15
- response = self.class.get("#{@options[:base_uri]}#{path}", { :query => query, :basic_auth => @auth })
16
- perform(response)
12
+ url = URI.parse("#{@options[:base_uri]}#{path}")
13
+ req = Net::HTTP::Get.new(url.path)
14
+ req.basic_auth @auth[:username], @auth[:password]
15
+ res = Net::HTTP.start(url.host, url.port) do |http|
16
+ response = http.request(req)
17
+ perform(response)
18
+ end
17
19
  end
18
20
 
19
21
 
20
22
  def perform_post(path, query={})
21
- response = self.class.post("#{@options[:base_uri]}#{path}", { :query => query, :basic_auth => @auth })
22
- perform(response)
23
+ url = URI.parse("#{@options[:base_uri]}#{path}")
24
+ req = Net::HTTP::Post.new(url.path)
25
+ req.basic_auth @auth[:username], @auth[:password]
26
+ req.set_form_data(query)
27
+ res = Net::HTTP.start(url.host, url.port) do |http|
28
+ response = http.request(req)
29
+ perform(response)
30
+ end
23
31
  end
24
32
 
25
33
 
data/lib/hydrogen.rb CHANGED
@@ -1,5 +1,7 @@
1
+ require 'net/http'
2
+ require 'uri'
1
3
  require 'rubygems'
2
- require 'httparty'
4
+ require 'crack'
3
5
  require 'mash'
4
6
 
5
7
 
@@ -0,0 +1 @@
1
+ {"comment":{"comment_id":1,"parent":0,"text":"first comment","created":"Thu, 27 Aug 2009 21:28:55 +0000","creator":"Matt Kirman"}}
@@ -0,0 +1 @@
1
+ {"comments":[{"comment_id":1,"parent":0,"text":"first comment","created":"Thu, 27 Aug 2009 21:28:55 +0000","creator":"Matt Kirman"}, {"comment_id":2,"parent":1,"text":"reply to first comment","created":"Thu, 27 Aug 2009 23:28:55 +0000","creator":"Matt Kirman"}]}
@@ -0,0 +1 @@
1
+ {"comment":{"comment_id":3,"parent":0,"text":"This is a test comment","created":"Sun, 27 Sep 2009 15:09:55 +0000","creator":"Matt Kirman"}}
@@ -0,0 +1 @@
1
+ {"topic":{"topic_id":1,"title":"This is a test question","text":"","type":"question","product":"Hydrogen","tags":["test","question"],"status":4,"private":false,"created":"Tue, 25 Aug 2009 15:07:43 +0000","creator":"Matt Kirman","comments":1,"updated":"Thu, 27 Aug 2009 21:28:55 +0000"}}
@@ -0,0 +1 @@
1
+ true
@@ -0,0 +1 @@
1
+ {"topic":{"topic_id":1,"title":"This is a test question","text":"","type":"question","product":"Hydrogen","tags":["test","question"],"status":4,"private":false,"created":"Tue, 25 Aug 2009 15:07:43 +0000","creator":"Matt Kirman","comments":1,"updated":"Thu, 27 Aug 2009 21:28:55 +0000"}}
@@ -0,0 +1 @@
1
+ {"topics":[{"topic_id":1,"title":"This is a test question","text":"","type":"question","product":"Hydrogen","tags":["test","question"],"status":4,"private":false,"created":"Tue, 25 Aug 2009 15:07:43 +0000","creator":"Matt Kirman","comments":1,"updated":"Thu, 27 Aug 2009 21:28:55 +0000"},{"topic_id":2,"title":"And another test topic","text":"","type":"praise","product":null,"tags":[""],"status":4,"private":false,"created":"Tue, 25 Aug 2009 15:03:50 +0000","creator":"Matt Kirman","comments":0}]}
@@ -0,0 +1,81 @@
1
+ require 'test_helper'
2
+
3
+ class BaseTest < Test::Unit::TestCase
4
+ context "#base" do
5
+ setup do
6
+ @hydrogen = Hydrogen::Base.new('redflex', 'username', 'password')
7
+ end
8
+
9
+
10
+ context "initialize" do
11
+ should "require a client" do
12
+ @hydrogen.should respond_to('topics')
13
+ @hydrogen.should respond_to('comments')
14
+ end
15
+ end
16
+
17
+
18
+ context "hitting the api" do
19
+ should "be able to get topics" do
20
+ stub_get('/topics.json', 'topics.json')
21
+ topics = @hydrogen.topics
22
+ topics.size.should == 2
23
+ first = topics.first
24
+ first.topic_id.should == 1
25
+ first.creator.should == 'Matt Kirman'
26
+ first.tags.is_a?(Array).should == true
27
+ first.tags[0].should == 'test'
28
+ first.private.should be(false)
29
+ end
30
+
31
+ should "be able to get a single topic" do
32
+ stub_get('/topics/1.json', 'topic.json')
33
+ topic = @hydrogen.topic(1)
34
+ topic.creator.should == 'Matt Kirman'
35
+ topic.tags.is_a?(Array).should be(true)
36
+ topic.tags[0].should == 'test'
37
+ topic.private.should be(false)
38
+ end
39
+
40
+ should "be able to create a topic" do
41
+ stub_post('/topics/create.json', 'create_topic.json')
42
+ topic = @hydrogen.create_topic({ :title => 'Test topic', :type => 'question' })
43
+ topic.creator.should == 'Matt Kirman'
44
+ topic.tags.is_a?(Array).should be(true)
45
+ topic.tags[0].should == 'test'
46
+ topic.private.should be(false)
47
+ end
48
+
49
+ should "be able to delete a topic" do
50
+ stub_get('/topics/1/delete.json', 'delete_topic.json')
51
+ response = @hydrogen.delete_topic(1)
52
+ response.should be(true)
53
+ end
54
+
55
+ should "be able to get topic comments" do
56
+ stub_get('/topics/1/comments.json', 'comments.json')
57
+ comments = @hydrogen.comments(1)
58
+ comments.size.should == 2
59
+ first = comments.first
60
+ first.comment_id.should == 1
61
+ first.creator.should == 'Matt Kirman'
62
+ end
63
+
64
+ should "be able to get a single topic comment" do
65
+ stub_get('/topics/1/comments/1.json', 'comment.json')
66
+ comment = @hydrogen.comment(1,1)
67
+ comment.comment_id.should == 1
68
+ comment.creator.should == 'Matt Kirman'
69
+ end
70
+
71
+ should "be able to create a new topic comment" do
72
+ stub_post('/topics/1/comments/create.json', 'create_comment.json')
73
+ comment = @hydrogen.create_comment(1, { :comment => 'This is a test comment' })
74
+ comment.comment_id.should == 3
75
+ comment.creator.should == 'Matt Kirman'
76
+ comment.text.should == 'This is a test comment'
77
+ end
78
+ end
79
+
80
+ end
81
+ end
@@ -0,0 +1,48 @@
1
+ require 'test/unit'
2
+ require 'pathname'
3
+ require 'rubygems'
4
+
5
+ gem 'thoughtbot-shoulda', '>= 2.10.1'
6
+ gem 'jnunemaker-matchy', '>= 0.4.0'
7
+ gem 'mocha', '>= 0.9.4'
8
+ gem 'fakeweb', '>= 1.2.5'
9
+
10
+ require 'shoulda'
11
+ require 'matchy'
12
+ require 'mocha'
13
+ require 'fakeweb'
14
+
15
+ FakeWeb.allow_net_connect = false
16
+
17
+ dir = (Pathname(__FILE__).dirname + '../lib').expand_path
18
+ require dir + 'hydrogen'
19
+
20
+
21
+ class Test::Unit::TestCase
22
+ end
23
+
24
+
25
+ def fixture_file(filename)
26
+ return '' if filename == ''
27
+
28
+ file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename)
29
+ File.read(file_path)
30
+ end
31
+
32
+
33
+ def hydrogen_url(url)
34
+ url =~ /^http/ ? url : "http://username:password@redflex.hydrogenapp.com:80#{url}"
35
+ end
36
+
37
+
38
+ def stub_get(url, filename, status=nil)
39
+ options = {:body => fixture_file(filename)}
40
+ options.merge!({:status => status}) unless status.nil?
41
+
42
+ FakeWeb.register_uri(:get, hydrogen_url(url), options)
43
+ end
44
+
45
+
46
+ def stub_post(url, filename)
47
+ FakeWeb.register_uri(:post, hydrogen_url(url), :body => fixture_file(filename))
48
+ end
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.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Kirman
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-26 00:00:00 -07:00
12
+ date: 2009-09-27 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -22,14 +22,23 @@ extensions: []
22
22
  extra_rdoc_files:
23
23
  - README.md
24
24
  files:
25
- - History.txt
26
25
  - README.md
27
26
  - VERSION.yml
28
27
  - lib/hydrogen.rb
29
28
  - lib/hydrogen/base.rb
30
29
  - lib/hydrogen/request.rb
30
+ - test/fixtures/comment.json
31
+ - test/fixtures/comments.json
32
+ - test/fixtures/create_comment.json
33
+ - test/fixtures/create_topic.json
34
+ - test/fixtures/delete_topic.json
35
+ - test/fixtures/topic.json
36
+ - test/fixtures/topics.json
37
+ - test/hydrogen/base_test.rb
38
+ - test/test_helper.rb
31
39
  has_rdoc: false
32
- homepage: http://redflex.co.uk/products/hydrogen
40
+ homepage: http://github.com/redflex/hydrogen-ruby
41
+ licenses:
33
42
  post_install_message:
34
43
  rdoc_options:
35
44
  - --charset=UTF-8
@@ -50,9 +59,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
50
59
  requirements: []
51
60
 
52
61
  rubyforge_project: hydrogen
53
- rubygems_version: 1.2.0
62
+ rubygems_version: 1.3.5
54
63
  signing_key:
55
64
  specification_version: 3
56
65
  summary: A Ruby implementation of the Hydrogen API.
57
- test_files: []
58
-
66
+ test_files:
67
+ - test/hydrogen/base_test.rb
68
+ - test/test_helper.rb
data/History.txt DELETED
File without changes