ardekantur-wondercroc 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +68 -0
- data/TODO +4 -0
- data/lib/wondercroc.rb +1 -0
- data/lib/wondercroc/client.rb +95 -0
- data/lib/{folder.rb → wondercroc/folder.rb} +10 -10
- data/lib/{location.rb → wondercroc/location.rb} +18 -3
- data/lib/{subscription.rb → wondercroc/subscription.rb} +1 -1
- metadata +25 -27
- data/README +0 -0
- data/lib/client.rb +0 -92
- data/spec/folder_spec.rb +0 -7
- data/wondercroc.gemspec +0 -21
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 YOUR NAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'hanna/rdoctask'
|
3
|
+
require 'rake/gempackagetask'
|
4
|
+
require 'rubygems/specification'
|
5
|
+
require 'date'
|
6
|
+
require 'spec/rake/spectask'
|
7
|
+
require 'spec/rake/verify_rcov'
|
8
|
+
|
9
|
+
|
10
|
+
GEM = "wondercroc"
|
11
|
+
GEM_VERSION = "0.0.4"
|
12
|
+
AUTHOR = "Ardekantur"
|
13
|
+
EMAIL = "greystone@ardekantur.com"
|
14
|
+
HOMEPAGE = "http://github.com/ardekantur/wondercroc"
|
15
|
+
SUMMARY = "a ruby api for interacting with the newsgator feed synchronization service"
|
16
|
+
|
17
|
+
spec = Gem::Specification.new do |s|
|
18
|
+
s.name = GEM
|
19
|
+
s.version = GEM_VERSION
|
20
|
+
s.platform = Gem::Platform::RUBY
|
21
|
+
s.has_rdoc = true
|
22
|
+
s.extra_rdoc_files = ["README.rdoc", "LICENSE", 'TODO']
|
23
|
+
s.summary = SUMMARY
|
24
|
+
s.description = s.summary
|
25
|
+
s.author = AUTHOR
|
26
|
+
s.email = EMAIL
|
27
|
+
s.homepage = HOMEPAGE
|
28
|
+
|
29
|
+
# Uncomment this to add a dependency
|
30
|
+
# s.add_dependency "foo"
|
31
|
+
|
32
|
+
s.require_path = 'lib'
|
33
|
+
s.autorequire = GEM
|
34
|
+
s.files = %w(LICENSE README.rdoc Rakefile TODO) + Dir.glob("{lib,specs}/**/*")
|
35
|
+
end
|
36
|
+
|
37
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
38
|
+
pkg.gem_spec = spec
|
39
|
+
end
|
40
|
+
|
41
|
+
desc "install the gem locally"
|
42
|
+
task :install => [:package] do
|
43
|
+
sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
|
44
|
+
end
|
45
|
+
|
46
|
+
desc "create a gemspec file"
|
47
|
+
task :make_spec do
|
48
|
+
File.open("#{GEM}.gemspec", "w") do |file|
|
49
|
+
file.puts spec.to_ruby
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
desc "generate rdoc documentation"
|
54
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
55
|
+
rdoc.rdoc_files.include('README.rdoc', 'LICENSE', 'TODO').
|
56
|
+
include('lib/**/*.rb')
|
57
|
+
|
58
|
+
rdoc.main = "README.rdoc"
|
59
|
+
rdoc.rdoc_dir = 'doc' # rdoc output folder
|
60
|
+
end
|
61
|
+
|
62
|
+
desc "Run RSpec and Rcov"
|
63
|
+
Spec::Rake::SpecTask.new("spec:rcov") do |t|
|
64
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
65
|
+
t.rcov_opts = ['--exclude', "spec/,rcov.rb,rspec.rb,spec*"]
|
66
|
+
t.rcov = true
|
67
|
+
t.rcov_dir = 'doc/coverage'
|
68
|
+
end
|
data/TODO
ADDED
data/lib/wondercroc.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
%w{ client folder location subscription }.each { |x| require "wondercroc/#{x}" }
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rest_client'
|
3
|
+
require 'rexml/document'
|
4
|
+
require 'rss/2.0'
|
5
|
+
|
6
|
+
# NewsGator is a Ruby layer for interacting with the
|
7
|
+
# NewsGator API.
|
8
|
+
|
9
|
+
module WonderCroc
|
10
|
+
|
11
|
+
class Client
|
12
|
+
|
13
|
+
VERSION = [ 0, 0, 4 ].join '.'
|
14
|
+
SERVICE = "http://services.newsgator.com/ngws/svc"
|
15
|
+
|
16
|
+
BULLETIN_TOKEN = {
|
17
|
+
"X-NGAPITOKEN" => "A8BBE03745F2439287D9425AB4BFFC30",
|
18
|
+
"User-Agent" => "wondercroc/#{VERSION}",
|
19
|
+
"Accept-Encoding" => "compress,gzip"
|
20
|
+
}
|
21
|
+
|
22
|
+
attr_accessor :response
|
23
|
+
attr_accessor :folders
|
24
|
+
|
25
|
+
# Initializes an instance of a NewsGator Client.
|
26
|
+
# +config_obj+ is a hash consisting of the keys
|
27
|
+
# +:name+, +:password+, and +:location+, if you do
|
28
|
+
# not want WonderCroc auto-generating a location name.
|
29
|
+
def initialize config_obj
|
30
|
+
@config = config_obj
|
31
|
+
@folder_unread_counts = {}
|
32
|
+
self.clear_locations
|
33
|
+
end
|
34
|
+
|
35
|
+
def get_feed id, unread = true
|
36
|
+
new_connection_to "/Feed.aspx/#{id}?unread=#{unread.to_s.capitalize}"
|
37
|
+
send_request :get
|
38
|
+
end
|
39
|
+
|
40
|
+
def get_random_feed
|
41
|
+
raise "no feeds" unless @subscriptions
|
42
|
+
get_feed @subscriptions[(rand * @subscriptions.length).floor].id, false
|
43
|
+
end
|
44
|
+
|
45
|
+
def parse_stories
|
46
|
+
p = RSS::Parser.new @response
|
47
|
+
p.do_validate = false
|
48
|
+
p.parse
|
49
|
+
end
|
50
|
+
|
51
|
+
def get_unread_counts ui = nil
|
52
|
+
ui.update_status 'Getting subscription counts...' if ui
|
53
|
+
new_connection_to "/Subscription.aspx/#{@location[:id]}/subscriptionCounts"
|
54
|
+
send_request :get
|
55
|
+
doc = REXML::Document.new @response
|
56
|
+
REXML::XPath.each(doc, "descendant-or-self::*") do |e|
|
57
|
+
@folder_unread_counts[e.attributes['ng:folderId']] = @folder_unread_counts.fetch(e.attributes['ng:folderId'], 0) + e.attributes['ng:unreadCount'].to_i
|
58
|
+
end
|
59
|
+
@folders.flatten.each { |f| f.unread_count = @folder_unread_counts.fetch(f.id, 0) }
|
60
|
+
ui.update_status ''
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def new_connection_to url
|
66
|
+
@request = RestClient::Resource.new(SERVICE + url, @config[:user], @config[:password])
|
67
|
+
end
|
68
|
+
|
69
|
+
def send_request type, headers = {}
|
70
|
+
raise ArgumentError, "invalid send request type #{type}" unless [ :get, :delete ].include? type
|
71
|
+
@response = @request.send type, BULLETIN_TOKEN.merge(headers)
|
72
|
+
end
|
73
|
+
|
74
|
+
def send_data type, payload, headers = {}
|
75
|
+
raise ArgumentError, "invalid send data request type #{type}" unless [ :put, :post ].include? type
|
76
|
+
@response = @request.send type, payload, BULLETIN_TOKEN.merge(headers)
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
class RSS::Rss::Channel::Item
|
83
|
+
[
|
84
|
+
["read", :boolean ],
|
85
|
+
["id", :integer ],
|
86
|
+
["postId", :integer ],
|
87
|
+
["avgRating", :float ],
|
88
|
+
["clipped", :boolean ],
|
89
|
+
["token", :text ],
|
90
|
+
["folderId", :text ]
|
91
|
+
].each do |elem, type|
|
92
|
+
install_text_element "ng:#{elem}", "http://newsgator.com/schema/extensions", '?', "#{elem}", type, "ng:#{elem}"
|
93
|
+
RSS::BaseListener.install_get_text_element "http://newsgator.com/schema/extensions", "#{elem}", "#{elem}="
|
94
|
+
end
|
95
|
+
end
|
@@ -19,7 +19,16 @@ class Folder
|
|
19
19
|
|
20
20
|
end
|
21
21
|
|
22
|
-
class
|
22
|
+
class Client
|
23
|
+
|
24
|
+
# Return a list of all folders in the user's subscription.
|
25
|
+
def get_folders
|
26
|
+
new_connection_to "/Folder.aspx"
|
27
|
+
send_request :get
|
28
|
+
@folders = folders_from_xml(@response)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
23
32
|
|
24
33
|
def folders_from_xml xml
|
25
34
|
folders = []
|
@@ -42,15 +51,6 @@ class NewsGatorClient
|
|
42
51
|
|
43
52
|
return folders.compact
|
44
53
|
end
|
45
|
-
|
46
|
-
private
|
47
|
-
|
48
|
-
# Return a list of all folders in the user's subscription.
|
49
|
-
def get_folders
|
50
|
-
new_connection_to "/Folder.aspx"
|
51
|
-
send_request :get
|
52
|
-
@folders = folders_from_xml(@response)
|
53
|
-
end
|
54
54
|
|
55
55
|
end
|
56
56
|
|
@@ -1,18 +1,25 @@
|
|
1
1
|
module WonderCroc
|
2
|
-
|
2
|
+
|
3
|
+
class Client
|
3
4
|
|
4
5
|
# Emptys the location cache.
|
5
6
|
def clear_locations
|
6
7
|
@locations = []
|
7
8
|
end
|
8
9
|
|
10
|
+
# Sets the location from the configuration hash passed through
|
11
|
+
# at the instantsiation of the Client object. If a +:location+
|
12
|
+
# key was not passed with that has, the location name is generated
|
13
|
+
# like so: 'newsgator_account_name-MACHINE_HOSTNAME'.
|
9
14
|
def set_location_from_config
|
10
15
|
get_locations
|
11
|
-
@location
|
16
|
+
@config[:location] ||= "#{@config[:user]}-#{`hostname`.strip.upcase}"
|
17
|
+
@location = @locations.find { |l| l[:title] == @config[:location] }
|
12
18
|
raise "no location found for name #{@config.location}" unless @location
|
13
19
|
end
|
14
20
|
|
15
|
-
# Retrieves a list of all
|
21
|
+
# Retrieves a list of all the locations that the logged in user
|
22
|
+
# has available.
|
16
23
|
def get_locations
|
17
24
|
clear_locations
|
18
25
|
new_connection_to '/Location.aspx'
|
@@ -25,6 +32,9 @@ class NewsGatorClient
|
|
25
32
|
return nil
|
26
33
|
end
|
27
34
|
|
35
|
+
# Deletes a location from the online service.
|
36
|
+
# This does not require any kind of confirmation, and
|
37
|
+
# is permanent for all intents and purposes.
|
28
38
|
def delete_location id
|
29
39
|
new_connection_to "/Location.aspx/#{id}"
|
30
40
|
send_request :delete
|
@@ -36,6 +46,11 @@ class NewsGatorClient
|
|
36
46
|
@subscriptions = subscriptions_from_xml(@response)
|
37
47
|
end
|
38
48
|
|
49
|
+
# Adds a location to the online service.
|
50
|
+
# +name+ is the name of the location, +add_subscriptions+
|
51
|
+
# is a boolean option corresponding to whether or not
|
52
|
+
# subscriptions are automatically added to this location
|
53
|
+
# whenever the user subscribes to a new feed.
|
39
54
|
def add_location name, add_subscriptions = true
|
40
55
|
new_connection_to "/Location.aspx"
|
41
56
|
payload = <<-OPML
|
metadata
CHANGED
@@ -1,42 +1,40 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ardekantur-wondercroc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ardekantur
|
8
|
-
autorequire:
|
8
|
+
autorequire: wondercroc
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-07-01 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
16
|
-
|
17
|
-
version_requirement:
|
18
|
-
version_requirements: !ruby/object:Gem::Requirement
|
19
|
-
requirements:
|
20
|
-
- - ">="
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: "0"
|
23
|
-
version:
|
24
|
-
description: ""
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: a ruby api for interacting with the newsgator feed synchronization service
|
25
17
|
email: greystone@ardekantur.com
|
26
18
|
executables: []
|
27
19
|
|
28
20
|
extensions: []
|
29
21
|
|
30
|
-
extra_rdoc_files:
|
31
|
-
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
- LICENSE
|
25
|
+
- TODO
|
32
26
|
files:
|
33
|
-
-
|
34
|
-
- README
|
35
|
-
-
|
36
|
-
-
|
37
|
-
- lib/
|
38
|
-
- lib/
|
39
|
-
|
27
|
+
- LICENSE
|
28
|
+
- README.rdoc
|
29
|
+
- Rakefile
|
30
|
+
- TODO
|
31
|
+
- lib/wondercroc
|
32
|
+
- lib/wondercroc/client.rb
|
33
|
+
- lib/wondercroc/folder.rb
|
34
|
+
- lib/wondercroc/location.rb
|
35
|
+
- lib/wondercroc/subscription.rb
|
36
|
+
- lib/wondercroc.rb
|
37
|
+
has_rdoc: true
|
40
38
|
homepage: http://github.com/ardekantur/wondercroc
|
41
39
|
post_install_message:
|
42
40
|
rdoc_options: []
|
@@ -58,9 +56,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
56
|
requirements: []
|
59
57
|
|
60
58
|
rubyforge_project:
|
61
|
-
rubygems_version: 1.0
|
59
|
+
rubygems_version: 1.2.0
|
62
60
|
signing_key:
|
63
61
|
specification_version: 2
|
64
|
-
summary: a ruby api for interacting with the newsgator feed synchronization service
|
65
|
-
test_files:
|
66
|
-
|
62
|
+
summary: a ruby api for interacting with the newsgator feed synchronization service
|
63
|
+
test_files: []
|
64
|
+
|
data/README
DELETED
File without changes
|
data/lib/client.rb
DELETED
@@ -1,92 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'rest_client'
|
3
|
-
require 'rexml/document'
|
4
|
-
require 'rss/2.0'
|
5
|
-
|
6
|
-
# NewsGator is a Ruby layer for interacting with the
|
7
|
-
# NewsGator API.
|
8
|
-
|
9
|
-
module WonderCroc
|
10
|
-
class NewsGatorClient
|
11
|
-
|
12
|
-
VERSION = [ 0, 0, 3 ].join '.'
|
13
|
-
SERVICE = "http://services.newsgator.com/ngws/svc"
|
14
|
-
|
15
|
-
BULLETIN_TOKEN = {
|
16
|
-
"X-NGAPITOKEN" => "A8BBE03745F2439287D9425AB4BFFC30",
|
17
|
-
"User-Agent" => "bulletin/#{VERSION}",
|
18
|
-
"Accept-Encoding" => "compress,gzip"
|
19
|
-
}
|
20
|
-
|
21
|
-
attr_accessor :response
|
22
|
-
attr_accessor :folders
|
23
|
-
|
24
|
-
# Initializes an instance of a NewsGator connection
|
25
|
-
# with the provided +Configuration+ object.
|
26
|
-
def initialize config_obj
|
27
|
-
@config = config_obj
|
28
|
-
@folder_unread_counts = {}
|
29
|
-
self.clear_locations
|
30
|
-
end
|
31
|
-
|
32
|
-
def get_feed id, unread = true
|
33
|
-
new_connection_to "/Feed.aspx/#{id}?unread=#{unread.to_s.capitalize}"
|
34
|
-
send_request :get
|
35
|
-
end
|
36
|
-
|
37
|
-
def get_random_feed
|
38
|
-
raise "no feeds" unless @subscriptions
|
39
|
-
get_feed @subscriptions[(rand * @subscriptions.length).floor].id, false
|
40
|
-
end
|
41
|
-
|
42
|
-
def parse_stories
|
43
|
-
p = RSS::Parser.new @response
|
44
|
-
p.do_validate = false
|
45
|
-
p.parse
|
46
|
-
end
|
47
|
-
|
48
|
-
def get_unread_counts ui = nil
|
49
|
-
ui.update_status 'Getting subscription counts...' if ui
|
50
|
-
new_connection_to "/Subscription.aspx/#{@location[:id]}/subscriptionCounts"
|
51
|
-
send_request :get
|
52
|
-
doc = REXML::Document.new @response
|
53
|
-
REXML::XPath.each(doc, "descendant-or-self::*") do |e|
|
54
|
-
@folder_unread_counts[e.attributes['ng:folderId']] = @folder_unread_counts.fetch(e.attributes['ng:folderId'], 0) + e.attributes['ng:unreadCount'].to_i
|
55
|
-
end
|
56
|
-
@folders.flatten.each { |f| f.unread_count = @folder_unread_counts.fetch(f.id, 0) }
|
57
|
-
ui.update_status ''
|
58
|
-
end
|
59
|
-
|
60
|
-
private
|
61
|
-
|
62
|
-
def new_connection_to url
|
63
|
-
@request = RestClient::Resource.new(SERVICE + url, @config.user, @config.password)
|
64
|
-
end
|
65
|
-
|
66
|
-
def send_request type, headers = {}
|
67
|
-
raise ArgumentError, "invalid send request type #{type}" unless [ :get, :delete ].include? type
|
68
|
-
@response = @request.send type, BULLETIN_TOKEN.merge(headers)
|
69
|
-
end
|
70
|
-
|
71
|
-
def send_data type, payload, headers = {}
|
72
|
-
raise ArgumentError, "invalid send data request type #{type}" unless [ :put, :post ].include? type
|
73
|
-
@response = @request.send type, payload, BULLETIN_TOKEN.merge(headers)
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
class RSS::Rss::Channel::Item
|
80
|
-
[
|
81
|
-
["read", :boolean ],
|
82
|
-
["id", :integer ],
|
83
|
-
["postId", :integer ],
|
84
|
-
["avgRating", :float ],
|
85
|
-
["clipped", :boolean ],
|
86
|
-
["token", :text ],
|
87
|
-
["folderId", :text ]
|
88
|
-
].each do |elem, type|
|
89
|
-
install_text_element "ng:#{elem}", "http://newsgator.com/schema/extensions", '?', "#{elem}", type, "ng:#{elem}"
|
90
|
-
RSS::BaseListener.install_get_text_element "http://newsgator.com/schema/extensions", "#{elem}", "#{elem}="
|
91
|
-
end
|
92
|
-
end
|
data/spec/folder_spec.rb
DELETED
data/wondercroc.gemspec
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
Gem::Specification.new do |s|
|
2
|
-
s.name = "wondercroc"
|
3
|
-
s.version = "0.0.3"
|
4
|
-
s.date = "2008-06-24"
|
5
|
-
s.summary = "a ruby api for interacting with the newsgator feed synchronization service."
|
6
|
-
s.email = "greystone@ardekantur.com"
|
7
|
-
s.homepage = "http://github.com/ardekantur/wondercroc"
|
8
|
-
s.description = ""
|
9
|
-
s.has_rdoc = false
|
10
|
-
s.authors = ["Ardekantur"]
|
11
|
-
s.require_path = "lib"
|
12
|
-
s.files = [ "wondercroc.gemspec", "README", "lib/client.rb", "lib/folder.rb", "lib/location.rb", "lib/subscription.rb"]
|
13
|
-
s.test_files = ["spec/folder_spec.rb"]
|
14
|
-
s.add_dependency('rest_client')
|
15
|
-
=begin
|
16
|
-
s.test_files = ["test/test_actor.rb", "test/test_blob.rb", "test/test_commit.rb", "test/test_config.rb", "test/test_diff.rb", "test/test_git.rb", "test/test_head.rb", "test/test_real.rb", "test/test_reality.rb", "test/test_repo.rb", "test/test_tag.rb", "test/test_tree.rb"]
|
17
|
-
s.rdoc_options = ["--main", "README.txt"]
|
18
|
-
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
|
19
|
-
s.add_dependency("mime-types", ["> 0.0.0"])
|
20
|
-
=end
|
21
|
-
end
|