rawapi 0.1.1

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/CHANGELOG.txt ADDED
File without changes
data/History.txt ADDED
File without changes
data/Manifest.txt ADDED
@@ -0,0 +1,11 @@
1
+ CHANGELOG.txt
2
+ History.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+
7
+ lib/rawapi.rb
8
+ lib/rawapi/version.rb
9
+ setup.rb
10
+ test/test_helper.rb
11
+ test/test_rawapi.rb
data/README.txt ADDED
@@ -0,0 +1,3 @@
1
+ README for rawapi
2
+ =================
3
+
data/Rakefile ADDED
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/clean'
4
+ require 'rake/testtask'
5
+ require 'rake/packagetask'
6
+ require 'rake/gempackagetask'
7
+ require 'rake/rdoctask'
8
+ require 'rake/contrib/rubyforgepublisher'
9
+ require 'fileutils'
10
+ require 'hoe'
11
+ include FileUtils
12
+ require File.join(File.dirname(__FILE__), 'lib', 'rawapi', 'version')
13
+
14
+ AUTHOR = "Ben Wyrosdick" # can also be an array of Authors
15
+ EMAIL = "ben@commonthread.com"
16
+ DESCRIPTION = "Ruby interface to the FeedBurner Awareness API."
17
+ GEM_NAME = "rawapi" # what ppl will type to install your gem
18
+ RUBYFORGE_PROJECT = "rawapi" # The unix name for your project
19
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
20
+
21
+
22
+ NAME = "rawapi"
23
+ REV = nil # UNCOMMENT IF REQUIRED: File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
24
+ VERS = ENV['VERSION'] || (Rawapi::VERSION::STRING + (REV ? ".#{REV}" : ""))
25
+ CLEAN.include ['**/.*.sw?', '*.gem', '.config']
26
+ RDOC_OPTS = ['--quiet', '--title', "rawapi documentation",
27
+ "--opname", "index.html",
28
+ "--line-numbers",
29
+ "--main", "README",
30
+ "--inline-source"]
31
+
32
+ class Hoe
33
+ def extra_deps
34
+ @extra_deps.reject { |x| Array(x).first == 'hoe' }
35
+ end
36
+ end
37
+
38
+ # Generate all the Rake tasks
39
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
40
+ hoe = Hoe.new(GEM_NAME, VERS) do |p|
41
+ p.author = AUTHOR
42
+ p.description = DESCRIPTION
43
+ p.email = EMAIL
44
+ p.summary = DESCRIPTION
45
+ p.url = HOMEPATH
46
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
47
+ p.test_globs = ["test/**/*_test.rb"]
48
+ p.clean_globs = CLEAN #An array of file patterns to delete on clean.
49
+
50
+ # == Optional
51
+ #p.changes - A description of the release's latest changes.
52
+ #p.extra_deps - An array of rubygem dependencies.
53
+ #p.spec_extras - A hash of extra values to set in the gemspec.
54
+ end
@@ -0,0 +1,9 @@
1
+ module Rawapi #:nodoc:
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 1
5
+ BUILD = 1
6
+
7
+ STRING = [MAJOR, MINOR, BUILD].join('.')
8
+ end
9
+ end
data/lib/rawapi.rb ADDED
@@ -0,0 +1,92 @@
1
+ Dir[File.join(File.dirname(__FILE__), 'rawapi/**/*.rb')].sort.each { |lib| require lib }
2
+
3
+ require 'open-uri'
4
+ require 'rexml/document'
5
+ include REXML
6
+
7
+ class AwarenessApi
8
+ ROOT_API_URL = 'http://api.feedburner.com/awareness/1.0/'
9
+
10
+ def get_feed_data(options)
11
+ option_string = parse_options(options)
12
+
13
+ response_xml = open("#{ROOT_API_URL}GetFeedData?#{option_string}").read
14
+ return parse_xml(response_xml)
15
+ end
16
+
17
+ def get_item_data(options)
18
+ option_string = parse_options(options)
19
+
20
+ response_xml = open("#{ROOT_API_URL}GetItemData?#{option_string}").read
21
+ return parse_xml(response_xml)
22
+ end
23
+
24
+ # add GetResyndicationData
25
+ # def get_resyndication_data(options)
26
+ # option_string = parse_options(options)
27
+ #
28
+ # response_xml = open("#{ROOT_API_URL}GetResyndicationData?#{option_string}").read
29
+ # return parse_xml(response_xml)
30
+ # end
31
+
32
+ private
33
+ def parse_options(options)
34
+ raise "options must include a feed id or uri" unless options[:id] or options[:uri]
35
+
36
+ options[:uri] = nil if options[:id] and options[:uri]
37
+
38
+ return options.collect {|key, value| "#{key}=#{value}" unless value.nil?}.compact.join('&')
39
+ end
40
+
41
+ def parse_xml(response_xml)
42
+ response = Response.new
43
+
44
+ xml = Document.new(response_xml)
45
+ rsp_node = xml.root
46
+
47
+ response.status = rsp_node.attributes['stat']
48
+
49
+ if response.status == 'fail'
50
+ response.code = rsp_node.elements[1].attributes['code']
51
+ response.message = rsp_node.elements[1].attributes['msg']
52
+ elsif response.status == 'ok'
53
+ for feed_node in rsp_node.elements
54
+ feed = Feed.new
55
+
56
+ feed.id = feed_node.attributes['id']
57
+ feed.uri = feed_node.attributes['uri']
58
+
59
+ response.feeds << feed
60
+
61
+ for entry_node in feed_node.elements
62
+ entry = Entry.new
63
+
64
+ entry.date = entry_node.attributes['date']
65
+ entry.circulation = entry_node.attributes['circulation']
66
+ entry.hits = entry_node.attributes['hits']
67
+
68
+ feed.entries << entry
69
+
70
+ for item_node in entry_node.elements
71
+ item = Item.new
72
+
73
+ item.title = item_node.attributes['title']
74
+ item.url = item_node.attributes['url']
75
+ item.itemviews = item_node.attributes['itemviews']
76
+ item.clickthroughs = item_node.attributes['clickthroughs']
77
+
78
+ entry.items << item
79
+ end
80
+ end
81
+ end
82
+ end
83
+
84
+ return response
85
+ end
86
+ end
87
+
88
+ # rawapi = AwarenessApi.new
89
+ # opts = {:uri => 'CommonThread', :dates => '2007-03-20,2007-03-23'}
90
+ #
91
+ # puts rawapi.get_feed_data(opts)
92
+ # puts rawapi.get_item_data(opts)