jordandobson-glue 1.0.3 → 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.
- data/lib/glue.rb +20 -5
- data/test/test_glue.rb +5 -4
- metadata +1 -1
data/lib/glue.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'httparty'
|
3
|
-
require 'nokogiri'
|
4
3
|
require 'open-uri'
|
5
4
|
|
6
5
|
module Glue
|
7
6
|
|
8
|
-
VERSION = '1.0.
|
7
|
+
VERSION = '1.0.4'
|
9
8
|
DOMAIN = 'gluenow.com'
|
10
9
|
|
11
10
|
class AuthError < StandardError; end
|
@@ -15,6 +14,8 @@ module Glue
|
|
15
14
|
|
16
15
|
POST = '/api/post'
|
17
16
|
USER = '/api/user'
|
17
|
+
|
18
|
+
attr_accessor :site
|
18
19
|
|
19
20
|
def initialize subdomain, user, pass
|
20
21
|
raise AuthError, 'Username, Password or Account subdomain is blank.' \
|
@@ -25,15 +26,21 @@ module Glue
|
|
25
26
|
end
|
26
27
|
|
27
28
|
def valid_site?
|
28
|
-
|
29
|
+
login_page.match(/<body[^>]*id=["']login["']/) ? true : false
|
29
30
|
end
|
30
31
|
|
31
32
|
def user_info
|
32
|
-
self.class.post(
|
33
|
+
response = self.class.post(
|
34
|
+
USER,
|
35
|
+
:query => {},
|
36
|
+
:basic_auth => @auth
|
37
|
+
)
|
38
|
+
response['rsp'] ? response : {}
|
39
|
+
|
33
40
|
end
|
34
41
|
|
35
42
|
def post title, body, *opts
|
36
|
-
self.class.post(
|
43
|
+
response = self.class.post(
|
37
44
|
POST,
|
38
45
|
:query => {
|
39
46
|
:title => title,
|
@@ -42,6 +49,14 @@ module Glue
|
|
42
49
|
:author => opts.include?( :author ) },
|
43
50
|
:basic_auth => @auth
|
44
51
|
)
|
52
|
+
response['rsp'] ? response : {}
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def login_page
|
59
|
+
open("http://#{@site}").read
|
45
60
|
end
|
46
61
|
|
47
62
|
end
|
data/test/test_glue.rb
CHANGED
@@ -22,6 +22,7 @@ class TestGlue < Test::Unit::TestCase
|
|
22
22
|
@author = "Jordan"
|
23
23
|
|
24
24
|
@resp_fail = {}
|
25
|
+
@resp_html = {"html"=>{"head"=>{"title" => "GLUE | Web + Mobile Publishing"}}}
|
25
26
|
|
26
27
|
@resp_ok = { "rsp" => {
|
27
28
|
"user" => {
|
@@ -116,12 +117,12 @@ class TestGlue < Test::Unit::TestCase
|
|
116
117
|
end
|
117
118
|
|
118
119
|
def test_site_is_valid
|
119
|
-
|
120
|
+
@client.stubs(:login_page).returns('<html><body id="login"></body></html>')
|
120
121
|
assert @client.valid_site?
|
121
122
|
end
|
122
123
|
|
123
124
|
def test_site_is_invalid
|
124
|
-
|
125
|
+
@client.stubs(:login_page).returns('<html><body></body></html>')
|
125
126
|
assert !@client.valid_site?
|
126
127
|
end
|
127
128
|
|
@@ -136,13 +137,13 @@ class TestGlue < Test::Unit::TestCase
|
|
136
137
|
end
|
137
138
|
|
138
139
|
def test_user_info_invalid
|
139
|
-
Glue::API.stubs(:post).returns(@
|
140
|
+
Glue::API.stubs(:post).returns(@resp_html)
|
140
141
|
actual = @client.user_info
|
141
142
|
assert_equal @resp_fail, actual
|
142
143
|
end
|
143
144
|
|
144
145
|
def test_bad_post_response
|
145
|
-
Glue::API.stubs(:post).returns(@
|
146
|
+
#Glue::API.stubs(:post).returns(@resp_html)
|
146
147
|
actual = @client.post(@title, @body)
|
147
148
|
assert_equal @resp_fail, actual
|
148
149
|
end
|