rawapi 0.1.2 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
@@ -0,0 +1,3 @@
1
+ * 0.2.1
2
+ * 0.1.2
3
+ * 0.1.1
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2008 CommonThread, LLC
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,28 @@
1
+ AwAPI docs at http://code.google.com/apis/feedburner/awareness_api.html
2
+
3
+ == This Library
4
+
5
+ The Ruby Awareness API (rAwAPI) provides a ruby interface to the FeedBurner Awareness API (AwAPI)
6
+
7
+ == What is “Awareness?”
8
+
9
+ Feed Awareness describes the extent and frequency with which a publisher's feed and its content items are consumed, clicked on, and referred to by independent sources (i.e., "syndicated").
10
+
11
+ The following data characterizes Feed Awareness:
12
+
13
+ * Feed Circulation and Hits: Circulation is a daily measure of feed readership and popularity, recorded over the life of your feed. Hits are a raw measure of request traffic for your feed.
14
+ * Detailed Item Popularity: The popularity of each item published as determined by itemviews and clickthroughs.
15
+ * Item Syndication: Redisplay or repurposing of a feed's content on a third party website that generates traffic (as itemviews and clickthroughs).
16
+
17
+ The reports and charts you see when using The FeedBurner website are based on the same data. Using AwAPI, you can create your own analysis and tracking applications. It's your data. Display it your way!
18
+
19
+
20
+ == Example
21
+
22
+ require 'awareness_api'
23
+
24
+ opts = {:uri => 'CommonThread'}
25
+
26
+ puts AwarenessApi.get_feed_data(opts)
27
+ puts AwarenessApi.get_item_data(opts)
28
+ puts AwarenessApi.get_resyndication_data(opts)
data/demo.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'lib/awareness_api'
2
+
3
+ opts = {:uri => 'CommonThread'}
4
+
5
+ puts AwarenessApi.get_feed_data(opts)
6
+ puts AwarenessApi.get_item_data(opts)
7
+ puts AwarenessApi.get_resyndication_data(opts)
@@ -0,0 +1,9 @@
1
+ module AwarenessApi
2
+ class Entry
3
+ include AwarenessApi::FeedAttributes
4
+
5
+ def initialize
6
+ @items = []
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ module AwarenessApi
2
+ class Feed
3
+ include AwarenessApi::FeedAttributes
4
+
5
+ attr_accessor :id
6
+
7
+ def initialize
8
+ @entries = []
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ module AwarenessApi
2
+ class Item
3
+ include AwarenessApi::FeedAttributes
4
+
5
+ def initialize
6
+ @referers = []
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ module AwarenessApi
2
+ class Referer
3
+ include AwarenessApi::FeedAttributes
4
+ end
5
+ end
@@ -0,0 +1,43 @@
1
+ # The Response object is the ruby object version of the webservice response.
2
+ module AwarenessApi
3
+ class Response
4
+ attr_accessor :status, :code, :message, :feeds
5
+
6
+ def initialize
7
+ @feeds = []
8
+ end
9
+
10
+ def to_s
11
+ output = []
12
+ output << "Status: #{@status}"
13
+ output << "Code: #{@code}" if @code
14
+ output << "Message: #{@message}" if @message
15
+ for feed in @feeds
16
+ output << "-Feed"
17
+ feed.attributes.each do |key,val|
18
+ output << " #{key}: #{val}"
19
+ end
20
+ for entry in feed.entries
21
+ output << " -Entry"
22
+ entry.attributes.each do |key,val|
23
+ output << " #{key}: #{val}"
24
+ end
25
+ for item in entry.items
26
+ output << " -Item"
27
+ item.attributes.each do |key,val|
28
+ output << " #{key}: #{val}"
29
+ end
30
+ for referer in item.referers
31
+ output << " -Referer"
32
+ referer.attributes.each do |key,val|
33
+ output << " #{key}: #{val}"
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ return output.join("\n")
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,160 @@
1
+ require 'open-uri'
2
+ require 'rexml/document'
3
+ include REXML
4
+
5
+ #
6
+ # The Ruby Awareness API (rAwAPI) provides a ruby interface to the FeedBurner Awareness API (AwAPI)
7
+ #
8
+ # AwAPI docs at http://code.google.com/apis/feedburner/awareness_api.html
9
+ #
10
+ # In rAwAPI calls, date ranges may be expressed as follows:
11
+ #
12
+ # * Individual dates always use this format: YYYY-MM-DD
13
+ # * Date ranges are expressed with a comma: YYYY-MM-D1, YYYY-MM-D7 means all dates between and including D1 and D7
14
+ # * If a range is specified, the second date must always be later than the first date
15
+ # * A single date will be interpreted as a range of one date: YYYY-MM-D1 = YYYY-MM-D1, YYYY-MM-D1
16
+ # * Discrete ranges are separated by a slash: YYYY-MM-D1/YYYY-MM-D5/YYYY-MM-D7,YYYY-MM-D14 means D1 and D5 and all dates between and including D7 and D14. Multiple discrete ranges may also be provided by using multiple date parameters in a single GET request.
17
+ # * If no date is specified, Yesterday's date is assumed. "Current" is always yesterday's data. "Live" daily data is not yet available.
18
+ # * An individual date starts at 12am CDT (GMT -5) and ends 12am CDT the next day. Custom timezone support is not yet available.
19
+ #
20
+ module AwarenessApi
21
+ ROOT_API_URL = 'http://api.feedburner.com/awareness/1.0/'
22
+
23
+ #
24
+ # Current Basic Feed Awareness Data
25
+ #
26
+ # Arguments
27
+ # uri The URI of the feed (same as http://feeds.feedburner.com/<feeduri>) Must be used if id is not specified
28
+ # id The FeedBurner id of the feed (visible when editing a feed in your account, e.g., http://www.feedburner.com/fb/a/optimize?id=<id>). May be used instead if uri is not specified.
29
+ # dates Dates are used to specify the period for which data is need (see note on dates)
30
+ #
31
+ def self.get_feed_data(options)
32
+ raise "options must include a feed id or uri" unless options[:id] or options[:uri]
33
+ option_string = parse_options(options)
34
+
35
+ response_xml = open("#{ROOT_API_URL}GetFeedData?#{option_string}").read
36
+ return parse_xml(response_xml)
37
+ end
38
+
39
+ #
40
+ # Current Item Awareness Data
41
+ #
42
+ # Arguments
43
+ # uri The URI of the feed (same as http://feeds.feedburner.com/<feeduri>)
44
+ # itemurl The source URL of item (not the FeedBurner generated URL, but the original source URL). Multiple itemurl parameters may be provided in a single request in order to retrieve additional items.
45
+ # dates Dates are used to specify the period for which data is need (see note on dates)
46
+ #
47
+ def self.get_item_data(options)
48
+ raise "options must include a feed uri" unless options[:uri]
49
+ option_string = parse_options(options)
50
+
51
+ response_xml = open("#{ROOT_API_URL}GetItemData?#{option_string}").read
52
+ return parse_xml(response_xml)
53
+ end
54
+
55
+ #
56
+ # Current Item Resyndication Feed Awareness Data
57
+ #
58
+ # Arguments
59
+ # uri The URI of the feed (same as http://feeds.feedburner.com/<feeduri>)
60
+ # itemurl The source URL of item (not the FeedBurner generated URL, but the original source URL). Multiple itemurl parameters may be provided in a single request in order to retrieve additional items.
61
+ # dates Dates are used to specify the period for which data is need (see note on dates)
62
+ #
63
+ def self.get_resyndication_data(options)
64
+ raise "options must include a feed uri" unless options[:uri]
65
+ option_string = parse_options(options)
66
+
67
+ response_xml = open("#{ROOT_API_URL}GetResyndicationData?#{option_string}").read
68
+ return parse_xml(response_xml)
69
+ end
70
+
71
+ private
72
+ def self.parse_options(options)
73
+ options[:uri] = nil if options[:id] and options[:uri]
74
+
75
+ return options.collect {|key, value| "#{key}=#{value}" unless value.nil?}.compact.join('&')
76
+ end
77
+
78
+ def self.parse_xml(response_xml)
79
+ response = Response.new
80
+
81
+ xml = Document.new(response_xml)
82
+ rsp_node = xml.root
83
+
84
+ response.status = rsp_node.attributes['stat']
85
+
86
+ if response.status == 'fail'
87
+ response.code = rsp_node.elements[1].attributes['code']
88
+ response.message = rsp_node.elements[1].attributes['msg']
89
+ elsif response.status == 'ok'
90
+ for feed_node in rsp_node.elements
91
+ feed = Feed.new
92
+
93
+ feed_node.attributes.each do |key,value|
94
+ feed.send(key+"=", value)
95
+ end
96
+
97
+ response.feeds << feed
98
+
99
+ for entry_node in feed_node.elements
100
+ entry = Entry.new
101
+
102
+ entry_node.attributes.each do |key,value|
103
+ entry.send(key+"=", value)
104
+ end
105
+
106
+ feed.entries << entry
107
+
108
+ for item_node in entry_node.elements
109
+ item = Item.new
110
+
111
+ item_node.attributes.each do |key,value|
112
+ item.send(key+"=", value)
113
+ end
114
+
115
+ entry.items << item
116
+
117
+ for referer_node in item_node.elements
118
+ referer = Referer.new
119
+
120
+ referer_node.attributes.each do |key,value|
121
+ referer.send(key+"=", value)
122
+ end
123
+
124
+ item.referers << referer
125
+ end
126
+ end
127
+ end
128
+ end
129
+ end
130
+
131
+ return response
132
+ end
133
+
134
+ #
135
+ # Adds the dynamic attributes to each feed class
136
+ #
137
+ module FeedAttributes
138
+ def attributes
139
+ attribute_hash = {}
140
+
141
+ self.instance_variables.each do |var|
142
+ var_symbol = var[1..-1].to_sym
143
+ attribute_hash[var_symbol] = self.send(var_symbol) unless self.send(var_symbol).is_a?(Array)
144
+ end
145
+
146
+ attribute_hash
147
+ end
148
+
149
+ def method_missing(method, *params, &block)
150
+ method = method.to_s
151
+ if method =~ /=/
152
+ self.instance_variable_set("@#{method[0..-2]}", params[0])
153
+ else
154
+ self.instance_variable_get("@#{method}")
155
+ end
156
+ end
157
+ end
158
+ end
159
+
160
+ Dir[File.join(File.dirname(__FILE__), 'awareness_api/**/*.rb')].sort.each { |lib| require lib }
metadata CHANGED
@@ -1,60 +1,64 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.2
3
- specification_version: 1
4
2
  name: rawapi
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.1.2
7
- date: 2007-03-26 00:00:00 -05:00
8
- summary: Ruby interface to the FeedBurner Awareness API.
9
- require_paths:
10
- - lib
11
- email: ben@commonthread.com
12
- homepage: http://rawapi.rubyforge.org
13
- rubyforge_project: rawapi
14
- description: Ruby interface to the FeedBurner Awareness API.
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: 0.2.1
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Ben Wyrosdick
31
- files:
32
- - CHANGELOG.txt
33
- - History.txt
34
- - Manifest.txt
35
- - README.txt
36
- - Rakefile
37
- - lib/rawapi.rb
38
- - lib/rawapi/entry.rb
39
- - lib/rawapi/feed.rb
40
- - lib/rawapi/item.rb
41
- - lib/rawapi/response.rb
42
- - lib/rawapi/referer.rb
43
- - lib/rawapi/version.rb
44
- - setup.rb
45
- - test/test_helper.rb
46
- - test/test_rawapi.rb
47
- test_files: []
48
-
49
- rdoc_options: []
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
50
11
 
51
- extra_rdoc_files: []
12
+ date: 2008-03-05 00:00:00 -06:00
13
+ default_executable:
14
+ dependencies: []
52
15
 
16
+ description: The Ruby Awareness API (rAwAPI) provides a ruby interface to the FeedBurner Awareness API (AwAPI)
17
+ email: ben@commonthread.com
53
18
  executables: []
54
19
 
55
20
  extensions: []
56
21
 
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - README
26
+ - CHANGELOG
27
+ - LICENSE
28
+ - demo.rb
29
+ - lib/awareness_api.rb
30
+ - lib/awareness_api/entry.rb
31
+ - lib/awareness_api/feed.rb
32
+ - lib/awareness_api/item.rb
33
+ - lib/awareness_api/referer.rb
34
+ - lib/awareness_api/response.rb
35
+ - test/test_helper.rb
36
+ - test/test_rawapi.rb
37
+ has_rdoc: true
38
+ homepage: http://rubyforge.org/projects/rawapi/
39
+ post_install_message:
40
+ rdoc_options: []
41
+
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ version:
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
57
56
  requirements: []
58
57
 
59
- dependencies: []
58
+ rubyforge_project: rawapi
59
+ rubygems_version: 1.0.1
60
+ signing_key:
61
+ specification_version: 2
62
+ summary: The Ruby Awareness API (rAwAPI) provides a ruby interface to the FeedBurner Awareness API (AwAPI)
63
+ test_files: []
60
64
 
data/CHANGELOG.txt DELETED
File without changes
data/History.txt DELETED
File without changes
data/Manifest.txt DELETED
@@ -1,16 +0,0 @@
1
- CHANGELOG.txt
2
- History.txt
3
- Manifest.txt
4
- README.txt
5
- Rakefile
6
-
7
- lib/rawapi.rb
8
- lib/rawapi/entry.rb
9
- lib/rawapi/feed.rb
10
- lib/rawapi/item.rb
11
- lib/rawapi/response.rb
12
- lib/rawapi/referer.rb
13
- lib/rawapi/version.rb
14
- setup.rb
15
- test/test_helper.rb
16
- test/test_rawapi.rb
data/README.txt DELETED
@@ -1,3 +0,0 @@
1
- README for rawapi
2
- =================
3
-
data/Rakefile DELETED
@@ -1,54 +0,0 @@
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
data/lib/rawapi/entry.rb DELETED
@@ -1,7 +0,0 @@
1
- class Entry
2
- attr_accessor :date, :circulation, :hits, :items
3
-
4
- def initialize
5
- @items = []
6
- end
7
- end
data/lib/rawapi/feed.rb DELETED
@@ -1,7 +0,0 @@
1
- class Feed
2
- attr_accessor :id, :uri, :entries
3
-
4
- def initialize
5
- @entries = []
6
- end
7
- end
data/lib/rawapi/item.rb DELETED
@@ -1,7 +0,0 @@
1
- class Item
2
- attr_accessor :title, :url, :itemviews, :clickthroughs, :referers
3
-
4
- def initialize
5
- @referers = []
6
- end
7
- end
@@ -1,3 +0,0 @@
1
- class Referer
2
- attr_accessor :url, :itemviews, :clickthroughs
3
- end
@@ -1,42 +0,0 @@
1
- # The Response object is the ruby object version of the webservice response.
2
- class Response
3
- attr_accessor :status, :code, :message, :feeds
4
-
5
- def initialize
6
- @feeds = []
7
- end
8
-
9
- # returns a formated string representing the response object. good for debugging.
10
- def to_s
11
- output = []
12
- output << "Status: #{@status}"
13
- output << "Code: #{@code}" if @code
14
- output << "Message: #{@message}" if @message
15
- for feed in @feeds
16
- output << "-Feed"
17
- output << " Id: #{feed.id}" if feed.id
18
- output << " URI: #{feed.uri}" if feed.uri
19
- for entry in feed.entries
20
- output << " -Entry"
21
- output << " Date: #{entry.date}" if entry.date
22
- output << " Circulation: #{entry.circulation}" if entry.circulation
23
- output << " Hits: #{entry.hits}" if entry.hits
24
- for item in entry.items
25
- output << " -Item"
26
- output << " Title: #{item.title}" if item.title
27
- output << " URL: #{item.url}" if item.url
28
- output << " ItemViews: #{item.itemviews}" if item.itemviews
29
- output << " Clickthoughs: #{item.clickthroughs}" if item.clickthroughs
30
- for referer in item.referers
31
- output << " -Referer"
32
- output << " URL: #{referer.url}" if referer.url
33
- output << " ItemViews: #{referer.itemviews}" if referer.itemviews
34
- output << " Clickthoughs: #{referer.clickthroughs}" if referer.clickthroughs
35
- end
36
- end
37
- end
38
- end
39
-
40
- return output.join("\n")
41
- end
42
- end
@@ -1,9 +0,0 @@
1
- module Rawapi #:nodoc:
2
- module VERSION #:nodoc:
3
- MAJOR = 0
4
- MINOR = 1
5
- BUILD = 2
6
-
7
- STRING = [MAJOR, MINOR, BUILD].join('.')
8
- end
9
- end