happymapper 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest CHANGED
@@ -15,6 +15,7 @@ Manifest
15
15
  Rakefile
16
16
  README
17
17
  spec/fixtures/address.xml
18
+ spec/fixtures/analytics.xml
18
19
  spec/fixtures/commit.xml
19
20
  spec/fixtures/current_weather.xml
20
21
  spec/fixtures/family_tree.xml
data/happymapper.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{happymapper}
5
- s.version = "0.2.3"
5
+ s.version = "0.2.4"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["John Nunemaker"]
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.description = %q{object to xml mapping library}
11
11
  s.email = %q{nunemaker@gmail.com}
12
12
  s.extra_rdoc_files = ["lib/happymapper/attribute.rb", "lib/happymapper/element.rb", "lib/happymapper/item.rb", "lib/happymapper/version.rb", "lib/happymapper.rb", "README", "TODO"]
13
- s.files = ["examples/amazon.rb", "examples/current_weather.rb", "examples/dashed_elements.rb", "examples/post.rb", "examples/twitter.rb", "happymapper.gemspec", "History", "lib/happymapper/attribute.rb", "lib/happymapper/element.rb", "lib/happymapper/item.rb", "lib/happymapper/version.rb", "lib/happymapper.rb", "License", "Manifest", "Rakefile", "README", "spec/fixtures/address.xml", "spec/fixtures/commit.xml", "spec/fixtures/current_weather.xml", "spec/fixtures/family_tree.xml", "spec/fixtures/multiple_namespaces.xml", "spec/fixtures/pita.xml", "spec/fixtures/posts.xml", "spec/fixtures/product_default_namespace.xml", "spec/fixtures/product_no_namespace.xml", "spec/fixtures/product_single_namespace.xml", "spec/fixtures/radar.xml", "spec/fixtures/statuses.xml", "spec/happymapper_attribute_spec.rb", "spec/happymapper_element_spec.rb", "spec/happymapper_item_spec.rb", "spec/happymapper_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "TODO", "website/css/common.css", "website/index.html"]
13
+ s.files = ["examples/amazon.rb", "examples/current_weather.rb", "examples/dashed_elements.rb", "examples/post.rb", "examples/twitter.rb", "happymapper.gemspec", "History", "lib/happymapper/attribute.rb", "lib/happymapper/element.rb", "lib/happymapper/item.rb", "lib/happymapper/version.rb", "lib/happymapper.rb", "License", "Manifest", "Rakefile", "README", "spec/fixtures/address.xml", "spec/fixtures/analytics.xml", "spec/fixtures/commit.xml", "spec/fixtures/current_weather.xml", "spec/fixtures/family_tree.xml", "spec/fixtures/multiple_namespaces.xml", "spec/fixtures/pita.xml", "spec/fixtures/posts.xml", "spec/fixtures/product_default_namespace.xml", "spec/fixtures/product_no_namespace.xml", "spec/fixtures/product_single_namespace.xml", "spec/fixtures/radar.xml", "spec/fixtures/statuses.xml", "spec/happymapper_attribute_spec.rb", "spec/happymapper_element_spec.rb", "spec/happymapper_item_spec.rb", "spec/happymapper_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "TODO", "website/css/common.css", "website/index.html"]
14
14
  s.has_rdoc = true
15
15
  s.homepage = %q{http://happymapper.rubyforge.org}
16
16
  s.post_install_message = %q{May you have many happy mappings!}
data/lib/happymapper.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  dir = File.dirname(__FILE__)
2
- $:.unshift(dir) unless $:.include?(dir) || $:.include?(File.expand_path(dir))
3
2
 
4
3
  require 'date'
5
4
  require 'time'
@@ -86,14 +85,16 @@ module HappyMapper
86
85
  # namespace prefix registered here will propagate down
87
86
  namespaces = node.namespaces
88
87
  if namespaces && namespaces.default
89
- namespaces.default_prefix = DEFAULT_NS
88
+ already_assigned = namespaces.definitions.detect do |defn|
89
+ namespaces.default && namespaces.default.href == defn.href && defn.prefix
90
+ end
91
+ namespaces.default_prefix = DEFAULT_NS unless already_assigned
90
92
  namespace ||= DEFAULT_NS
91
93
  end
92
94
 
93
95
  xpath = root ? '/' : './/'
94
96
  xpath += "#{namespace}:" if namespace
95
97
  xpath += tag_name
96
- # puts "parse: #{xpath}"
97
98
 
98
99
  nodes = node.find(xpath)
99
100
  collection = nodes.collect do |n|
@@ -108,7 +109,7 @@ module HappyMapper
108
109
  obj.send("#{elem.method_name}=",
109
110
  elem.from_xml_node(n, namespace))
110
111
  end
111
-
112
+
112
113
  obj
113
114
  end
114
115
 
@@ -124,6 +125,6 @@ module HappyMapper
124
125
  end
125
126
  end
126
127
 
127
- require 'happymapper/item'
128
- require 'happymapper/attribute'
129
- require 'happymapper/element'
128
+ require File.join(dir, 'happymapper/item')
129
+ require File.join(dir, 'happymapper/attribute')
130
+ require File.join(dir, 'happymapper/element')
@@ -1,3 +1,3 @@
1
1
  module HappyMapper
2
- Version = '0.2.3'
2
+ Version = '0.2.4'
3
3
  end
@@ -0,0 +1,61 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <feed xmlns="http://www.w3.org/2005/Atom"
3
+ xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/"
4
+ xmlns:dxp="http://schemas.google.com/analytics/2009">
5
+ <id>http://www.google.com/analytics/feeds/accounts/nunemaker@gmail.com</id>
6
+ <updated>2009-04-22T23:21:23.000-07:00</updated>
7
+ <title type="text">Profile list for nunemaker@gmail.com</title>
8
+ <link rel="self" type="application/atom+xml"
9
+ href="http://www.google.com/analytics/feeds/accounts/default"/>
10
+ <author>
11
+ <name>Google Analytics</name>
12
+ </author>
13
+ <generator version="1.0">Google Analytics</generator>
14
+ <openSearch:totalResults>4</openSearch:totalResults>
15
+ <openSearch:startIndex>1</openSearch:startIndex>
16
+ <openSearch:itemsPerPage>4</openSearch:itemsPerPage>
17
+ <entry>
18
+ <id>http://www.google.com/analytics/feeds/accounts/ga:47912</id>
19
+ <updated>2008-11-24T12:11:32.000-08:00</updated>
20
+ <title type="text">addictedtonew.com</title>
21
+ <link rel="alternate" type="text/html" href="http://www.google.com/analytics"/>
22
+ <dxp:tableId>ga:47912</dxp:tableId>
23
+ <dxp:property name="ga:accountId" value="85301"/>
24
+ <dxp:property name="ga:accountName" value="addictedtonew.com"/>
25
+ <dxp:property name="ga:profileId" value="47912"/>
26
+ <dxp:property name="ga:webPropertyId" value="UA-85301-1"/>
27
+ </entry>
28
+ <entry>
29
+ <id>http://www.google.com/analytics/feeds/accounts/ga:1897579</id>
30
+ <updated>2008-11-24T12:11:32.000-08:00</updated>
31
+ <title type="text">railstips.org</title>
32
+ <link rel="alternate" type="text/html" href="http://www.google.com/analytics"/>
33
+ <dxp:tableId>ga:1897579</dxp:tableId>
34
+ <dxp:property name="ga:accountId" value="85301"/>
35
+ <dxp:property name="ga:accountName" value="addictedtonew.com"/>
36
+ <dxp:property name="ga:profileId" value="1897579"/>
37
+ <dxp:property name="ga:webPropertyId" value="UA-85301-7"/>
38
+ </entry>
39
+ <entry>
40
+ <id>http://www.google.com/analytics/feeds/accounts/ga:17132454</id>
41
+ <updated>2009-04-22T23:21:23.000-07:00</updated>
42
+ <title type="text">johnnunemaker.com</title>
43
+ <link rel="alternate" type="text/html" href="http://www.google.com/analytics"/>
44
+ <dxp:tableId>ga:17132454</dxp:tableId>
45
+ <dxp:property name="ga:accountId" value="85301"/>
46
+ <dxp:property name="ga:accountName" value="addictedtonew.com"/>
47
+ <dxp:property name="ga:profileId" value="17132454"/>
48
+ <dxp:property name="ga:webPropertyId" value="UA-85301-25"/>
49
+ </entry>
50
+ <entry>
51
+ <id>http://www.google.com/analytics/feeds/accounts/ga:17132478</id>
52
+ <updated>2009-04-22T23:21:23.000-07:00</updated>
53
+ <title type="text">harmonyapp.com</title>
54
+ <link rel="alternate" type="text/html" href="http://www.google.com/analytics"/>
55
+ <dxp:tableId>ga:17132478</dxp:tableId>
56
+ <dxp:property name="ga:accountId" value="85301"/>
57
+ <dxp:property name="ga:accountName" value="addictedtonew.com"/>
58
+ <dxp:property name="ga:profileId" value="17132478"/>
59
+ <dxp:property name="ga:webPropertyId" value="UA-85301-26"/>
60
+ </entry>
61
+ </feed>
@@ -2,6 +2,38 @@ require File.dirname(__FILE__) + '/spec_helper.rb'
2
2
  require 'pp'
3
3
  require 'uri'
4
4
 
5
+ module Analytics
6
+ class Property
7
+ include HappyMapper
8
+
9
+ tag 'property'
10
+ namespace 'dxp'
11
+ attribute :name, String
12
+ attribute :value, String
13
+ end
14
+
15
+ class Entry
16
+ include HappyMapper
17
+
18
+ tag 'entry'
19
+ element :id, String
20
+ element :updated, DateTime
21
+ element :title, String
22
+ element :table_id, String, :namespace => 'dxp', :tag => 'tableId'
23
+ has_many :properties, Property
24
+ end
25
+
26
+ class Feed
27
+ include HappyMapper
28
+
29
+ tag 'feed'
30
+ element :id, String
31
+ element :updated, DateTime
32
+ element :title, String
33
+ has_many :entries, Entry
34
+ end
35
+ end
36
+
5
37
  class Feature
6
38
  include HappyMapper
7
39
  element :name, String, :tag => '.|.//text()'
@@ -505,6 +537,20 @@ describe HappyMapper do
505
537
  track.tran_detail.cust_tran_id.should == '20090102-111321'
506
538
  end
507
539
 
540
+ it "should be able to parse google analytics api xml" do
541
+ data = Analytics::Feed.parse(fixture_file('analytics.xml'))
542
+ data.id.should == 'http://www.google.com/analytics/feeds/accounts/nunemaker@gmail.com'
543
+ data.entries.size.should == 4
544
+
545
+ entry = data.entries[0]
546
+ entry.title.should == 'addictedtonew.com'
547
+ entry.properties.size.should == 4
548
+
549
+ property = entry.properties[0]
550
+ property.name.should == 'ga:accountId'
551
+ property.value.should == '85301'
552
+ end
553
+
508
554
  xit "should parse family search xml" do
509
555
  tree = FamilySearch::FamilyTree.parse(fixture_file('family_tree.xml'))
510
556
  tree.version.should == '1.0.20071213.942'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: happymapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
@@ -64,6 +64,7 @@ files:
64
64
  - Rakefile
65
65
  - README
66
66
  - spec/fixtures/address.xml
67
+ - spec/fixtures/analytics.xml
67
68
  - spec/fixtures/commit.xml
68
69
  - spec/fixtures/current_weather.xml
69
70
  - spec/fixtures/family_tree.xml