glue 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2009-06-24
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
@@ -0,0 +1,7 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ bin/glue
6
+ lib/glue.rb
7
+ test/test_glue.rb
@@ -0,0 +1,127 @@
1
+ = glue
2
+
3
+ http://Glue.RubyForge.org
4
+
5
+ http://GlueNow.com
6
+
7
+ == DESCRIPTION:
8
+
9
+ The Glue gem enables posting to GlueNow.com API service using an account subdomain, username, password. In this version you can add a post by providing a title, body, optional author name and optional private settings. You can also access some basic info about a users account and check if their account info is valid.
10
+
11
+ You can also request public posts from an account using the same RSS that powers the many Glue feeds.
12
+
13
+ == FEATURES/PROBLEMS:
14
+
15
+ * To Add a new post Title & Body text must be included
16
+ * Access info about an account with successful login:
17
+ * Email Address
18
+ * If they are an admin
19
+ * Thier Author Name
20
+ * Can check if a subdomain is valid and belongs to an account
21
+ * Read all public posts
22
+ * This Gem is throughly tested
23
+ * Adding & Reading posts Only at this time
24
+ * You can't editor delete a posts yet
25
+ * No way to verify if a post has accepted the author name yet
26
+
27
+
28
+ == SYNOPSIS:
29
+
30
+ 1. Instantiate your account
31
+
32
+ * Provide the subdomain, username and password for http://Your-Account.GlueNow.com
33
+
34
+ account = Glue::API.new( "your-account", "j-username", "j-password" )
35
+
36
+ 2. Check if the account subdomain is valid
37
+
38
+ account.valid_site?
39
+
40
+ 3. Get more info about the user's account
41
+
42
+ response = account.user_info
43
+
44
+ response #=> {"rsp"=>{"user"=>{"author"=>"Jordan Dobson","admin"=>"true","email"=>"jordandobson@gmail.com"},"stat"=>"ok"}}
45
+
46
+ 4. Post your Content
47
+
48
+ * Both Title and Body are required - Set to a variable to check the response
49
+
50
+ response = account.post("My Title", "My Body")
51
+
52
+ * You can also choose to set the post as private and/or use the optional Author Name
53
+ * In this example we set false for not private and true to use the author name
54
+
55
+ response = account.post("My Title", "My Body", false, true)
56
+
57
+
58
+ 5. Get a success or error hash back
59
+
60
+ * A Successful response would look like this
61
+
62
+ response #=> {"rsp"=>{"post"=>{"title"=>"My Title","url"=>"http://bit.ly/sakIM","id"=>"14415","longurl"=>"http://jordandobson.com"},"stat"=>"ok"}}
63
+
64
+ * A Error response would be empty like this
65
+
66
+ response #=> {}
67
+
68
+ ----
69
+
70
+ 1. Instantiate your Reader with your account info
71
+
72
+ * Provide the subdomain for http://Your-Account.GlueNow.com
73
+
74
+ account = Glue::RSS.new( "your-account" )
75
+
76
+ 2. Request posts from the RSS feed
77
+
78
+ * If you want all of them don't include any limiting or range. Defaults to up to 999 posts on one page
79
+
80
+ response = account.feed
81
+
82
+ * If you want to limit the results include a limit (1-999) and which page (used for paging)
83
+
84
+ response = account.feed(10, 3)
85
+
86
+ 3. Get an RSS feed back or HTML page - These Examples are simplified to include most important nodes
87
+
88
+ * A successful RSS response would look like
89
+
90
+ response #=> {"rss"=>{"channel"=>{"item"=>{"pubDate"=>"Fri, 12 Sep 2008 00:00:00 +0000","title"=>"My Title","guid"=>"http://jordandobson.com#14415","dc:creator"=>"Jordan","description"=>"<p>My Body</p>","link"=>"http://jordandobson.com","source"=>"Glue"}}}}
91
+
92
+ * A failed HTML responsed would look like
93
+
94
+ response #=> {"html"=>{"head"=>{"title"=>"GLUE | Web + Mobile Content Publishing"},"body"=>"<p>Webpage Body</p>"}}
95
+
96
+ == REQUIREMENTS:
97
+
98
+ * Mechanize & HTTParty
99
+
100
+ == INSTALL:
101
+
102
+ * sudo gem install glue -include-dependencies
103
+
104
+ == LICENSE:
105
+
106
+ (The MIT License)
107
+
108
+ Copyright (c) 2009 Squad, Inc.
109
+
110
+ Permission is hereby granted, free of charge, to any person obtaining
111
+ a copy of this software and associated documentation files (the
112
+ 'Software'), to deal in the Software without restriction, including
113
+ without limitation the rights to use, copy, modify, merge, publish,
114
+ distribute, sublicense, and/or sell copies of the Software, and to
115
+ permit persons to whom the Software is furnished to do so, subject to
116
+ the following conditions:
117
+
118
+ The above copyright notice and this permission notice shall be
119
+ included in all copies or substantial portions of the Software.
120
+
121
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
122
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
123
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
124
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
125
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
126
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
127
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,14 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ require './lib/glue.rb'
6
+
7
+ Hoe.new('glue', Glue::VERSION) do |p|
8
+ p.developer('Jordan Dobson', 'jordan.dobson@madebysquad.com')
9
+ p.extra_deps = ['mechanize']
10
+ p.extra_deps = ['httparty']
11
+ p.extra_dev_deps = ['mocha']
12
+ end
13
+
14
+ # vim: syntax=Ruby
@@ -0,0 +1 @@
1
+ #!/usr/bin/env ruby
@@ -0,0 +1,64 @@
1
+ require 'rubygems'
2
+ require 'httparty'
3
+ require 'nokogiri'
4
+ require 'open-uri'
5
+
6
+ module Glue
7
+
8
+ VERSION = '0.0.1'
9
+ DOMAIN = 'gluenow.com'
10
+
11
+ class AuthError < StandardError; end
12
+ class FormatHelper; include HTTParty; format :xml; end
13
+
14
+ class API < Glue::FormatHelper
15
+
16
+ POST = '/api/post'
17
+ USER = '/api/user'
18
+
19
+ def initialize subdomain, user, pass
20
+ raise AuthError, 'Username, Password or Account subdomain is blank.' \
21
+ if subdomain.empty? || user.empty? || pass.empty?
22
+ @auth = { :username => user, :password => pass }
23
+ @site = "#{subdomain}.#{DOMAIN}"
24
+ self.class.base_uri @site
25
+ end
26
+
27
+ def valid_site?
28
+ Nokogiri::HTML(open("http://#{@site}")).at('body#login') ? true : false
29
+ end
30
+
31
+ def user_info
32
+ self.class.post(USER, :query => {}, :basic_auth => @auth)
33
+ end
34
+
35
+ def post title, body, *opts
36
+ self.class.post(
37
+ POST,
38
+ :query => {
39
+ :title => title,
40
+ :body => body,
41
+ :draft => opts.include?( :draft ) ,
42
+ :author => opts.include?( :author ) },
43
+ :basic_auth => @auth
44
+ )
45
+ end
46
+
47
+ end
48
+
49
+ class RSS < Glue::FormatHelper
50
+
51
+ NEWS = '/news/rss'
52
+
53
+ def initialize subdomain
54
+ raise AuthError, 'Account Subdomain is missing or blank' if subdomain.empty?
55
+ self.class.base_uri "#{subdomain}.#{DOMAIN}"
56
+ end
57
+
58
+ def feed limit=999, page=1
59
+ self.class.get("#{NEWS}?limit=#{limit}&page=#{page}")
60
+ end
61
+
62
+ end
63
+
64
+ end
@@ -0,0 +1,218 @@
1
+ require "test/unit"
2
+ require "#{File.dirname(__FILE__)}/../lib/glue.rb"
3
+ require "mocha"
4
+
5
+ class TestGlue < Test::Unit::TestCase
6
+
7
+ def setup
8
+ @subdomain = 'AccountSubDomain'
9
+ @username = 'Username'
10
+ @password = 'Password'
11
+ @client = Glue::API.new( @subdomain, @username, @password )
12
+ @title = "My Title"
13
+ @title2 = "Your Title"
14
+ @body = "Body Text"
15
+ @body2 = "Hello World"
16
+ @url = "http://bit.ly/sakIM"
17
+ @id = "14415"
18
+ @id2 = "14416"
19
+ @lurl = "http://jordandobson.com"
20
+ @guid = "#{@lurl}##{@id}"
21
+ @guid2 = "#{@lurl}##{@id2}"
22
+ @author = "Jordan"
23
+
24
+ @resp_fail = {}
25
+
26
+ @resp_ok = { "rsp" => {
27
+ "user" => {
28
+ "author" => @author,
29
+ "admin" => "true" ,
30
+ "email" => nil },
31
+ "stat" => "ok" }}
32
+
33
+ @post_ok = { "rsp" => {
34
+ "post" => {
35
+ "title" => @title ,
36
+ "url" => @url ,
37
+ "id" => @id ,
38
+ "longurl" => @lurl },
39
+ "stat" => "ok" }}
40
+
41
+ @rss = { "rss" => {
42
+ "channel" => {
43
+ "item" => {
44
+ "pubDate" => "Fri, 12 Sep 2008 00:00:00 +0000",
45
+ "title" => @title ,
46
+ "guid" => @guid ,
47
+ "dc:creator" => @author ,
48
+ "description" => "<p>#{@body}</p>" ,
49
+ "link" => @lurl ,
50
+ "source" => "Glue" }}}}
51
+
52
+ @rss_many = { "rss" => {
53
+ "channel" => {
54
+ "item" => [{
55
+ "pubDate" => "Fri, 12 Sep 2008 00:00:00 +0000",
56
+ "title" => @title ,
57
+ "guid" => @guid ,
58
+ "dc:creator" => @author ,
59
+ "description" => "<p>#{@body}</p>" ,
60
+ "link" => @lurl ,
61
+ "source" => "Glue" },{
62
+ "pubDate" => "Fri, 12 Sep 2009 00:00:00 +0000",
63
+ "title" => @title2 ,
64
+ "guid" => @guid2 ,
65
+ "dc:creator" => nil ,
66
+ "description" => "<p>#{@body2}</p>" ,
67
+ "link" => @lurl ,
68
+ "source" => "Glue" }]}}}
69
+
70
+ @rss_empty = { "rss" => {
71
+ "channel" => {
72
+ "pubDate" => "Tue, 18 Aug 2009 10:48:28 +0000" ,
73
+ "webMaster" => "glue@jordan.gluenow.com (Glue)" ,
74
+ "link" => "http://jordandobson.com" }}}
75
+
76
+ @html_page = { "html" => {
77
+ "head" => {
78
+ "title" => "GLUE | Web + Mobile Content Publishing" },
79
+ "body" => "<p>Webpage Body</p>" }}
80
+ end
81
+
82
+ def test_raises_without_account_url
83
+ assert_raise Glue::AuthError do
84
+ Glue::API.new( '' , @username, @password )
85
+ end
86
+ end
87
+
88
+ def test_raises_without_user
89
+ assert_raise Glue::AuthError do
90
+ Glue::API.new( @subdomain, '', @password )
91
+ end
92
+ end
93
+
94
+ def test_raises_without_password
95
+ assert_raise Glue::AuthError do
96
+ Glue::API.new( @subdomain, @username, '' )
97
+ end
98
+ end
99
+
100
+ def test_raises_with_number_account_url
101
+ assert_raise NoMethodError do
102
+ Glue::API.new( 00 , @username, @password )
103
+ end
104
+ end
105
+
106
+ def test_raises_with_number_user
107
+ assert_raise NoMethodError do
108
+ Glue::API.new( @subdomain, 00, @password )
109
+ end
110
+ end
111
+
112
+ def test_raises_with_number_password
113
+ assert_raise NoMethodError do
114
+ Glue::API.new( @subdomain, @username, 00 )
115
+ end
116
+ end
117
+
118
+ def test_site_is_valid
119
+ OpenURI.stubs(:open_uri).returns('<body id="login"></body>')
120
+ assert @client.valid_site?
121
+ end
122
+
123
+ def test_site_is_invalid
124
+ OpenURI.stubs(:open_uri).returns('<body></body>')
125
+ assert !@client.valid_site?
126
+ end
127
+
128
+ def test_user_info_valid
129
+ Glue::API.stubs(:post).returns(@resp_ok)
130
+ actual = @client.user_info
131
+ assert_equal "ok", actual["rsp"]["stat"]
132
+ assert actual["rsp"]["user"]
133
+ assert_equal "Jordan", actual["rsp"]["user"]["author"]
134
+ assert_equal "true", actual["rsp"]["user"]["admin"]
135
+ assert_equal nil, actual["rsp"]["user"]["email"]
136
+ end
137
+
138
+ def test_user_info_invalid
139
+ Glue::API.stubs(:post).returns(@resp_fail)
140
+ actual = @client.user_info
141
+ assert_equal @resp_fail, actual
142
+ end
143
+
144
+ def test_bad_post_response
145
+ Glue::API.stubs(:post).returns(@resp_fail)
146
+ actual = @client.post(@title, @body)
147
+ assert_equal @resp_fail, actual
148
+ end
149
+
150
+ def test_good_post_response
151
+ Glue::API.stubs(:post).returns(@post_ok)
152
+ actual = @client.post(@title, @body)
153
+ assert_equal "ok", actual["rsp"]["stat"]
154
+ assert actual["rsp"]["post"]
155
+ assert_equal @title, actual["rsp"]["post"]["title"]
156
+ assert_equal @url, actual["rsp"]["post"]["url"]
157
+ assert_equal @id, actual["rsp"]["post"]["id"]
158
+ assert_equal @lurl, actual["rsp"]["post"]["longurl"]
159
+ end
160
+
161
+ # Need to test pusting with the options
162
+
163
+ def test_reading_single_post
164
+ Glue::RSS.stubs(:get).returns(@rss)
165
+ actual = Glue::RSS.new('jordan').feed(1,1)['rss']['channel']["item"]
166
+ assert_equal @title, actual["title"]
167
+ assert_match @body, actual["description"]
168
+ assert_equal @lurl, actual["link"]
169
+ assert_equal @guid, actual["guid"]
170
+ assert_equal @author, actual["dc:creator"]
171
+ end
172
+
173
+ def test_reading_multiple_posts
174
+ Glue::RSS.stubs(:get).returns(@rss_many)
175
+ actual = Glue::RSS.new('jordan').feed['rss']['channel']["item"]
176
+ assert_equal 2, actual.length
177
+
178
+ # First Article
179
+ assert_equal @title, actual.first["title"]
180
+ assert_match @body, actual.first["description"]
181
+ assert_equal @lurl, actual.first["link"]
182
+ assert_equal @guid, actual.first["guid"]
183
+ assert_equal @author, actual.first["dc:creator"]
184
+
185
+ # Last Article
186
+ assert_equal @title2, actual.last["title"]
187
+ assert_match @body2, actual.last["description"]
188
+ assert_equal nil, actual.last["dc:creator"]
189
+ assert_equal @lurl, actual.last["link"]
190
+ assert_equal @guid2, actual.last["guid"]
191
+
192
+ assert_not_equal actual.first["title"], actual.last["title"]
193
+ assert_not_equal actual.first["description"], actual.last["description"]
194
+ assert_not_equal actual.first["dc:creator"], actual.last["dc:creator"]
195
+ assert_not_equal actual.first["guid"], actual.last["guid"]
196
+ assert_equal actual.first["link"], actual.last["link"]
197
+ end
198
+
199
+ def test_no_public_posts_available
200
+ Glue::RSS.stubs(:get).returns(@rss_empty)
201
+ subdomain = 'jordan'
202
+ actual = Glue::RSS.new(subdomain).feed
203
+ assert actual["rss"]["channel"]
204
+ assert_nil actual["rss"]["channel"]["item"]
205
+ assert_match subdomain, actual["rss"]["channel"]["webMaster"]
206
+ end
207
+
208
+ def test_bad_url
209
+ Glue::RSS.stubs(:get).returns(@html_page)
210
+ actual = Glue::RSS.new('666-DIE-666').feed
211
+ assert actual["html"]
212
+ assert_nil actual["rss"]
213
+ assert_raise NoMethodError do
214
+ actual["rss"]["channel"]
215
+ end
216
+ end
217
+
218
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: glue
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jordan Dobson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-18 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: httparty
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: mocha
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: hoe
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.12.2
44
+ version:
45
+ description: |-
46
+ The Glue gem enables posting to GlueNow.com API service using an account subdomain, username, password. In this version you can add a post by providing a title, body, optional author name and optional private settings. You can also access some basic info about a users account and check if their account info is valid.
47
+
48
+ You can also request public posts from an account using the same RSS that powers the many Glue feeds.
49
+ email:
50
+ - jordan.dobson@madebysquad.com
51
+ executables:
52
+ - glue
53
+ extensions: []
54
+
55
+ extra_rdoc_files:
56
+ - History.txt
57
+ - Manifest.txt
58
+ - README.txt
59
+ files:
60
+ - History.txt
61
+ - Manifest.txt
62
+ - README.txt
63
+ - Rakefile
64
+ - bin/glue
65
+ - lib/glue.rb
66
+ - test/test_glue.rb
67
+ has_rdoc: true
68
+ homepage: http://Glue.RubyForge.org
69
+ licenses: []
70
+
71
+ post_install_message:
72
+ rdoc_options:
73
+ - --main
74
+ - README.txt
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: "0"
82
+ version:
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: "0"
88
+ version:
89
+ requirements: []
90
+
91
+ rubyforge_project: glue
92
+ rubygems_version: 1.3.3
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: The Glue gem enables posting to GlueNow.com API service using an account subdomain, username, password
96
+ test_files:
97
+ - test/test_glue.rb