Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

segment management api

  • Loading branch information...
commit 2a1cf104fc4ccd52ffe013d6a41a1cd165e24102 1 parent b3327a4
Tony Pitale tpitale authored
1  lib/garb.rb
@@ -33,6 +33,7 @@
33 33
34 34 # management
35 35 require 'garb/management/feed'
  36 +require 'garb/management/segment'
36 37 require 'garb/management/account'
37 38 require 'garb/management/web_property'
38 39 require 'garb/management/profile'
3  lib/garb/management/account.rb
@@ -5,8 +5,7 @@ class Account
5 5 attr_accessor :id, :title, :name
6 6
7 7 def self.all(session = Session)
8   - feed = Feed.new(session, '/accounts') # builds request and parses response
9   -
  8 + feed = Feed.new(session, '/accounts')
10 9 feed.entries.map {|entry| new_from_entry(entry, session)}
11 10 end
12 11
27 lib/garb/management/segment.rb
... ... @@ -0,0 +1,27 @@
  1 +module Garb
  2 + module Management
  3 + class Segment
  4 + attr_accessor :session, :path
  5 + attr_accessor :id, :name, :definition
  6 +
  7 + def self.all(session = Session)
  8 + feed = Feed.new(session, '/segments')
  9 + feed.entries.map {|entry| new_from_entry(entry, session)}
  10 + end
  11 +
  12 + def self.new_from_entry(entry, session)
  13 + segment = new
  14 + segment.session = session
  15 + segment.path = Garb.parse_link(entry, "self").gsub(Feed::BASE_URL, '')
  16 + segment.properties = entry['dxp:segment']
  17 + segment
  18 + end
  19 +
  20 + def properties=(properties)
  21 + self.id = properties['id']
  22 + self.name = properties['name']
  23 + self.definition = properties['dxp:definition']
  24 + end
  25 + end
  26 + end
  27 +end
47 test/unit/garb/management/segment_test.rb
... ... @@ -0,0 +1,47 @@
  1 +require 'test_helper'
  2 +
  3 +module Garb
  4 + module Management
  5 + class SegmentTest < MiniTest::Unit::TestCase
  6 + context "The Segment class" do
  7 + should "turn entries for path into array of accounts" do
  8 + feed = stub(:entries => ["entry1"])
  9 + Feed.stubs(:new).returns(feed)
  10 +
  11 + Segment.stubs(:new_from_entry)
  12 + Segment.all
  13 +
  14 + assert_received(Feed, :new) {|e| e.with(Session, '/segments')}
  15 + assert_received(feed, :entries)
  16 + assert_received(Segment, :new_from_entry) {|e| e.with("entry1", Session)}
  17 + end
  18 + end
  19 +
  20 + context "A Segment" do
  21 + setup do
  22 + entry = {
  23 + "link" => [{"rel" => "self", "href" => Feed::BASE_URL+"/segments/12"}],
  24 + "dxp:segment" => {
  25 + "id" => "gaid::-3",
  26 + "name" => "Returning Visitor",
  27 + "dxp:definition" => "ga:visitorType==Returning Visitor"
  28 + }
  29 + }
  30 + @segment = Segment.new_from_entry(entry, Session)
  31 + end
  32 +
  33 + should "have an id" do
  34 + assert_equal "gaid::-3", @segment.id
  35 + end
  36 +
  37 + should "have a name" do
  38 + assert_equal "Returning Visitor", @segment.name
  39 + end
  40 +
  41 + should "have a definition" do
  42 + assert_equal "ga:visitorType==Returning Visitor", @segment.definition
  43 + end
  44 + end
  45 + end
  46 + end
  47 +end

0 comments on commit 2a1cf10

Please sign in to comment.
Something went wrong with that request. Please try again.