salsa_labs 0.0.2.alpha → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 47ec06a20ffc63c76de20bb1b485975570f28eb5
4
- data.tar.gz: 0a059ad4f635a74052e1f3306e52e016169920e2
3
+ metadata.gz: f959fc08bf03b183bc7192bfe57e88cd6000bea6
4
+ data.tar.gz: a16c2bf7e35a05622c185d1e96c758db622ed42c
5
5
  SHA512:
6
- metadata.gz: e5e1c9420a5905b6c8c8736caf9f668b47a1a85aca7bbee516c8c3fb875da62a9259e2f6a73ad5dff4a312be199b4f4fbc45a733dbf2435cc15599e8867763b0
7
- data.tar.gz: b9d8561c84221ec1c9540975b3c42ab9f0a6e92a603ad00b17b82bd38f4daef82154876dfb3deaccc5da52d5987d602272b951294630d04c7b6b2819647ff9a2
6
+ metadata.gz: d445949a492a7ab0ecb613973504c2be89720d823eb68ef358ba978040a8f8557a98a6694c410368d73526368f75ef86e266d29a091a70a679de73a91c62d9fa
7
+ data.tar.gz: cc0c9eed3af1871df89eaee964b23ec54881cd6a7b5f36de37a4a16d20754a2f1c9164ba40243ad70e181a9e62895836029efc8042a2ea0ad414137d06d878f0
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  coverage
2
2
  *.gem
3
3
  tmp
4
+ .idea
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ salsa_labs
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.0.0
data/.travis.yml CHANGED
@@ -4,7 +4,3 @@ rvm:
4
4
  - 2.0.0
5
5
  - 2.1.0
6
6
  - jruby-19mode
7
- - rbx-2.1.1
8
- - ruby-head
9
- - jruby-head
10
- - ree
data/Gemfile.lock CHANGED
@@ -11,6 +11,12 @@ GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
13
  addressable (2.3.5)
14
+ celluloid (0.15.2)
15
+ timers (~> 1.1.0)
16
+ celluloid-io (0.15.0)
17
+ celluloid (>= 0.15.0)
18
+ nio4r (>= 0.5.0)
19
+ coderay (1.1.0)
14
20
  crack (0.4.1)
15
21
  safe_yaml (~> 0.9.0)
16
22
  diff-lcs (1.2.5)
@@ -18,16 +24,43 @@ GEM
18
24
  dotenv (0.9.0)
19
25
  faraday (0.8.8)
20
26
  multipart-post (~> 1.2.0)
27
+ ffi (1.9.3)
28
+ formatador (0.2.4)
29
+ guard (2.5.1)
30
+ formatador (>= 0.2.4)
31
+ listen (~> 2.6)
32
+ lumberjack (~> 1.0)
33
+ pry (>= 0.9.12)
34
+ thor (>= 0.18.1)
35
+ guard-rspec (4.2.8)
36
+ guard (~> 2.1)
37
+ rspec (>= 2.14, < 4.0)
21
38
  httparty (0.12.0)
22
39
  json (~> 1.8)
23
40
  multi_xml (>= 0.5.2)
24
41
  json (1.8.1)
42
+ listen (2.7.0)
43
+ celluloid (>= 0.15.2)
44
+ celluloid-io (>= 0.15.0)
45
+ rb-fsevent (>= 0.9.3)
46
+ rb-inotify (>= 0.9)
47
+ lumberjack (1.0.4)
48
+ method_source (0.8.2)
25
49
  mini_portile (0.5.2)
26
50
  multi_json (1.8.2)
27
51
  multi_xml (0.5.5)
28
52
  multipart-post (1.2.0)
53
+ nio4r (1.0.0)
29
54
  nokogiri (1.6.1)
30
55
  mini_portile (~> 0.5.0)
56
+ pry (0.9.12.6)
57
+ coderay (~> 1.0)
58
+ method_source (~> 0.8)
59
+ slop (~> 3.4)
60
+ rake (10.1.1)
61
+ rb-fsevent (0.9.4)
62
+ rb-inotify (0.9.3)
63
+ ffi (>= 0.5.0)
31
64
  rspec (2.14.1)
32
65
  rspec-core (~> 2.14.0)
33
66
  rspec-expectations (~> 2.14.0)
@@ -42,6 +75,9 @@ GEM
42
75
  multi_json
43
76
  simplecov-html (~> 0.8.0)
44
77
  simplecov-html (0.8.0)
78
+ slop (3.4.7)
79
+ thor (0.18.1)
80
+ timers (1.1.0)
45
81
  vcr (2.8.0)
46
82
  webmock (1.16.1)
47
83
  addressable (>= 2.2.7)
@@ -51,6 +87,9 @@ PLATFORMS
51
87
  ruby
52
88
 
53
89
  DEPENDENCIES
90
+ guard
91
+ guard-rspec
92
+ rake (~> 10.1.1)
54
93
  rspec (~> 2.14)
55
94
  salsa_labs!
56
95
  simplecov (~> 0.8)
data/Guardfile ADDED
@@ -0,0 +1,24 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :rspec do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ # Rails example
10
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
+ watch('config/routes.rb') { "spec/routing" }
15
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
+
17
+ # Capybara features specs
18
+ watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
19
+
20
+ # Turnip features and steps
21
+ watch(%r{^spec/acceptance/(.+)\.feature$})
22
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
23
+ end
24
+
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  Version](https://badge.fury.io/rb/salsa_labs.png)](http://badge.fury.io/rb/salsa_labs)
5
5
  [![Build Status](https://travis-ci.org/VelocityStrategies/ruby-salsa_labs.png?branch=master)](https://travis-ci.org/VelocityStrategies/ruby-salsa_labs)
6
6
  [![Dependency Status](https://gemnasium.com/VelocityStrategies/ruby-salsa_labs.png)](https://gemnasium.com/VelocityStrategies/ruby-salsa_labs)
7
- [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/VelocityStrategies/ruby-salsa_labs)
7
+ [![Code Climate](https://codeclimate.com/github/VelocityStrategies/ruby-salsa_labs.png)](https://codeclimate.com/github/VelocityStrategies/ruby-salsa_labs)
8
8
 
9
9
  ``salsa_labs`` can fetch data from the [Salsa Labs](http://salsalabs.com) API.
10
10
 
@@ -24,9 +24,9 @@ Or install it yourself as:
24
24
 
25
25
  ## Usage
26
26
 
27
- By default, you can store your API credentials as the environment variables ``SALSA_LABS_API_EMAIL`` and ``SALSA_LABS_API_PASSWORD`` to avoid the need to re-enter your password multiple times. Otherwise you will need to pass your credentials into the ``SalsaLabs::ApiClient`` or appropriate fetching method as you call it.
27
+ By default, you can store your API credentials as the environment variables `SALSA_LABS_API_EMAIL` and `SALSA_LABS_API_PASSWORD` to avoid the need to re-enter your password multiple times. Otherwise you will need to pass your credentials into the ``SalsaLabs::ApiClient`` or appropriate fetching method as you call it.
28
28
 
29
- ``SalsaLabs::ApiClient`` is a general-purpose object for performing GET requests from the Salsa API.
29
+ `SalsaLabs::ApiClient` is a general-purpose object for performing GET requests from the Salsa API.
30
30
 
31
31
  ```ruby
32
32
  # Create a client
@@ -45,7 +45,7 @@ client.fetch('getObjects.sjs', {object: 'Supporter', State: 'DC'})
45
45
  You can get a list of API calls and information about Salsa database objects here:
46
46
  [https://help.salsalabs.com/entries/23537918-Getting-data-from-Salsa](https://help.salsalabs.com/entries/23537918-Getting-data-from-Salsa)
47
47
 
48
- Currently specific functionality exists to work with Action campaigns, but more objects will be added later.
48
+ Currently specific functionality exists to work with Action campaigns(`SalsaLabs::Action`), Supporters (`SalsaLabs::Supporter`), and the join table Supporter Actions (`SalsaLabs::SupporterAction`), but more objects will be added later.
49
49
 
50
50
  ```ruby
51
51
  # Fetch all actions from Salsa. First argument is filter criteria, second argument is credentials if you are not storing them as environment variables.
@@ -57,7 +57,7 @@ actions.first.attributes
57
57
  # => {'title' => 'My Action Title', 'organization_key' => '90210', action_key => '1234'}
58
58
  ```
59
59
 
60
- ``SalsaLabs::Action#attributes`` returns a hash corresponding to all the attributes returned by the API, so it should accommodate custom fields and/or new fields added later by SalsaLabs. All attribute names are downcased.
60
+ `SalsaLabs::Action#attributes` returns a hash corresponding to all the attributes returned by the API, so it should accommodate custom fields and/or new fields added later by SalsaLabs. All attribute names are downcased.
61
61
 
62
62
  ## Dependencies
63
63
 
@@ -65,7 +65,7 @@ Ruby 1.9 is required.
65
65
 
66
66
  ## Credits
67
67
 
68
- The ``salsa_labs`` gem was created and is maintained by [Allison Sheren](http://github.com/asheren) and [Geoff Harcourt](http://github.com/geoffharcourt).
68
+ The `salsa_labs` gem was created and is maintained by [Allison Sheren](http://github.com/asheren) and [Geoff Harcourt](http://github.com/geoffharcourt).
69
69
 
70
70
  Development is generously sponsored by [Velocity](http://wearevelocity.com), in support of their work with progressive organizations.
71
71
 
@@ -79,6 +79,6 @@ Development is generously sponsored by [Velocity](http://wearevelocity.com), in
79
79
 
80
80
  ## License
81
81
 
82
- The ``salsa_labs`` gem is Copyright 2013-2014 Velocity. It is free software, and
82
+ The `salsa_labs` gem is Copyright 2013-2014 Velocity. It is free software, and
83
83
  may be redistributed under the terms of the MIT license, specified in the
84
84
  LICENSE file.
data/Rakefile CHANGED
@@ -1 +1,6 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -4,13 +4,6 @@ module SalsaLabs
4
4
  # the Salsa Labs / DemocracyInAction CRM.
5
5
  ##
6
6
  class Action < SalsaObject
7
-
8
- attr_reader :attributes
9
-
10
- def initialize(attributes)
11
- @attributes = attributes
12
- end
13
-
14
7
  def action_key
15
8
  (attributes['action_key'] || 0).to_i
16
9
  end
@@ -28,8 +21,8 @@ module SalsaLabs
28
21
  end
29
22
 
30
23
  def self.fetch(credentials = {})
31
- ActionsFetcher.new(credentials).fetch
24
+ ObjectsFetcher.fetch(type: 'Action', item_class: self,
25
+ credentials: credentials)
32
26
  end
33
-
34
27
  end
35
28
  end
@@ -0,0 +1,71 @@
1
+ module SalsaLabs
2
+ ##
3
+ # Service object that fetches a collection of objects from API and
4
+ # returns them as instances of a specified class
5
+ ##
6
+ class ObjectsFetcher
7
+ def self.fetch(opts = {})
8
+ filters = opts[:filters] || {}
9
+ credentials = opts[:credentials] || {}
10
+ client = SalsaLabs::ApiClient.new(credentials)
11
+ type = opts.fetch(:type)
12
+ item_class = opts[:item_class] || SalsaLabs::SalsaObject
13
+ new(filters: filters, client: client, type: type, item_class: item_class).fetch
14
+ end
15
+
16
+ def initialize(opts = {})
17
+ @filters = opts[:filters]
18
+ @client = opts[:client]
19
+ @type = opts[:type]
20
+ @item_class = opts[:item_class]
21
+ end
22
+
23
+ def fetch
24
+ item_nodes.map do |node|
25
+ item_class.new(SalsaLabsApiObjectNode.new(node).attributes)
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ attr_reader :client, :filters, :type, :item_class
32
+
33
+ def api_call
34
+ client.fetch('/api/getObjects.sjs', api_parameters)
35
+ end
36
+
37
+ def api_parameters
38
+ filters.merge(object: type)
39
+ end
40
+
41
+ def item_nodes
42
+ Nokogiri::XML(api_call).css('item')
43
+ end
44
+
45
+ ##
46
+ # Object used to translate API's XML node into a hash of attributes for
47
+ # SalsaLabs::Action creation.
48
+ ##
49
+ class SalsaLabsApiObjectNode
50
+
51
+ def initialize(xml_element)
52
+ @node = xml_element
53
+ end
54
+
55
+ def attributes
56
+ children.inject({}) do |memo, attribute|
57
+ memo[attribute.name.downcase] = attribute.text if attribute.element?
58
+ memo
59
+ end
60
+ end
61
+
62
+ private
63
+
64
+ attr_reader :node
65
+
66
+ def children
67
+ node.children
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,17 @@
1
+ module SalsaLabs
2
+ class Supporter < SalsaObject
3
+ def email
4
+ attributes['email']
5
+ end
6
+
7
+ def supporter_key
8
+ attributes['supporter_key'].to_i
9
+ end
10
+
11
+ def self.fetch(credentials = {})
12
+ ObjectsFetcher.fetch(credentials: credentials,
13
+ type: 'supporter',
14
+ item_class: self)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,21 @@
1
+ module SalsaLabs
2
+ class SupporterAction < SalsaObject
3
+ def supporter_key
4
+ attributes['supporter_key'].to_i if attributes['supporter_key']
5
+ end
6
+
7
+ def action_key
8
+ attributes['action_key'].to_i if attributes['action_key']
9
+ end
10
+
11
+ def supporter_action_key
12
+ attributes['supporter_action_key'].to_i if attributes['supporter_action_key']
13
+ end
14
+
15
+ def self.fetch(credentials = {})
16
+ ObjectsFetcher.fetch(type: 'supporter_action',
17
+ item_class: self,
18
+ credentials: credentials)
19
+ end
20
+ end
21
+ end
@@ -1,3 +1,3 @@
1
1
  module SalsaLabs
2
- VERSION = "0.0.2.alpha"
2
+ VERSION = '0.0.3'
3
3
  end
data/lib/salsa_labs.rb CHANGED
@@ -5,7 +5,9 @@ require 'salsa_labs/version'
5
5
  require 'salsa_labs/api_client'
6
6
  require 'salsa_labs/salsa_object'
7
7
  require 'salsa_labs/action'
8
- require 'salsa_labs/actions_fetcher'
8
+ require 'salsa_labs/supporter'
9
+ require 'salsa_labs/supporter_action'
10
+ require 'salsa_labs/objects_fetcher'
9
11
 
10
12
  module SalsaLabs
11
13
 
data/salsa_labs.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
10
10
  gem.email = ['asheren@gmail.com']
11
11
  gem.description = %q{A Ruby binding for the Salsa Labs (http://salsalabs.com) API.}
12
12
  gem.summary = %q{Salsa Labs' API contains information about supporters, donations, and actions. This gem faciliates pulling that information into a Ruby application.}
13
- gem.homepage = "http://github.com/geoffharcourt/ruby-salsa_labs"
13
+ gem.homepage = 'http://github.com/geoffharcourt/ruby-salsa_labs'
14
14
  gem.files = `git ls-files`.split($/)
15
15
  gem.test_files = gem.files.grep(%r{^(spec)/})
16
16
  gem.require_paths = ['lib']
@@ -21,9 +21,11 @@ Gem::Specification.new do |gem|
21
21
  gem.add_runtime_dependency 'httparty', '~> 0.12'
22
22
  gem.add_runtime_dependency 'nokogiri', '~> 1.5'
23
23
 
24
+ gem.add_development_dependency 'guard'
25
+ gem.add_development_dependency 'guard-rspec'
26
+ gem.add_development_dependency 'rake', '~> 10.1.1'
24
27
  gem.add_development_dependency 'rspec', '~> 2.14'
25
28
  gem.add_development_dependency 'simplecov', '~> 0.8'
26
29
  gem.add_development_dependency 'vcr', '~> 2.8'
27
30
  gem.add_development_dependency 'webmock', '~> 1.16'
28
-
29
31
  end
@@ -0,0 +1,68 @@
1
+ <?xml version="1.0"?>
2
+ <data organization_KEY="6120">
3
+ <supporter>
4
+ <item>
5
+ <supporter_KEY>31752865</supporter_KEY>
6
+ <organization_KEY>6120</organization_KEY>
7
+ <chapter_KEY/>
8
+ <Last_Modified>Fri Mar 19 2010 17:43:20 GMT-0400 (EDT)</Last_Modified>
9
+ <Date_Created>Thu Mar 11 2010 02:29:46 GMT-0500 (EST)</Date_Created>
10
+ <Title/>
11
+ <First_Name>Christopher</First_Name>
12
+ <MI/>
13
+ <Last_Name>Doorley</Last_Name>
14
+ <Suffix/>
15
+ <Email>chris@example.com</Email>
16
+ <Password/>
17
+ <Receive_Email>3</Receive_Email>
18
+ <Email_Status/>
19
+ <Email_Preference/>
20
+ <Soft_Bounce_Count>1</Soft_Bounce_Count>
21
+ <Hard_Bounce_Count/>
22
+ <Last_Bounce>Fri Mar 19 2010 17:43:20 GMT-0400 (EDT)</Last_Bounce>
23
+ <Receive_Phone_Blasts_BOOLVALUE>false</Receive_Phone_Blasts_BOOLVALUE>
24
+ <Receive_Phone_Blasts>false</Receive_Phone_Blasts>
25
+ <Phone/>
26
+ <Cell_Phone/>
27
+ <Phone_Provider/>
28
+ <Work_Phone/>
29
+ <Pager/>
30
+ <Home_Fax/>
31
+ <Work_Fax/>
32
+ <Street/>
33
+ <Street_2/>
34
+ <Street_3/>
35
+ <City/>
36
+ <State/>
37
+ <Zip/>
38
+ <PRIVATE_Zip_Plus_4>0000</PRIVATE_Zip_Plus_4>
39
+ <County/>
40
+ <District/>
41
+ <Country/>
42
+ <Latitude/>
43
+ <Longitude/>
44
+ <Organization>Velocity Strategies</Organization>
45
+ <Department/>
46
+ <Occupation/>
47
+ <Instant_Messenger_Service/>
48
+ <Instant_Messenger_Name/>
49
+ <Web_Page/>
50
+ <Alternative_Email/>
51
+ <Other_Data_1/>
52
+ <Other_Data_2/>
53
+ <Other_Data_3/>
54
+ <Notes/>
55
+ <Source>Web</Source>
56
+ <Source_Details>http://velocitystrategies.com/contact</Source_Details>
57
+ <Source_Tracking_Code>(No Original Source Available)</Source_Tracking_Code>
58
+ <Tracking_Code/>
59
+ <Status/>
60
+ <uid/>
61
+ <Timezone/>
62
+ <Language_Code/>
63
+ <BLOB0>This is a test of the email contact system.</BLOB0>
64
+ <key>31752865</key>
65
+ <object>supporter</object>
66
+ </item>
67
+ </supporter>
68
+ </data>
@@ -0,0 +1,19 @@
1
+ <?xml version="1.0"?>
2
+ <data organization_KEY="6120">
3
+ <supporter_action>
4
+ <item>
5
+ <supporter_action_KEY>898207</supporter_action_KEY>
6
+ <organization_KEY>0</organization_KEY>
7
+ <chapter_KEY/>
8
+ <supporter_KEY>123</supporter_KEY>
9
+ <action_KEY>234</action_KEY>
10
+ <Last_Modified>Sat Mar 13 2010 03:10:05 GMT-0500 (EST)</Last_Modified>
11
+ <Date_Created>Sat Mar 13 2010 03:10:05 GMT-0500 (EST)</Date_Created>
12
+ <supporter_action_comment_KEY/>
13
+ <Anonymous/>
14
+ <tracking_code/>
15
+ <key>898207</key>
16
+ <object>supporter_action</object>
17
+ </item>
18
+ </supporter_action>
19
+ </data>
@@ -51,17 +51,19 @@ describe SalsaLabs::Action do
51
51
  end
52
52
 
53
53
  describe ".fetch" do
54
- let(:actions_fetcher) { double('ActionsFetcher', fetch: []) }
54
+ let(:objects_fetcher) { double('ObjectsFetcher', fetch: []) }
55
55
 
56
56
  before(:each) do
57
- SalsaLabs::ActionsFetcher.stub(new: actions_fetcher)
57
+ SalsaLabs::ObjectsFetcher.stub(fetch: nil)
58
58
  end
59
59
 
60
- it "calls .fetch on an SalsaLabs::ActionsFetcher object" do
61
- SalsaLabs::Action.fetch
60
+ it "passes the credentials to actions fetcher" do
61
+ SalsaLabs::Action.fetch(email: 'foo@bar.com', password: 'pass')
62
62
 
63
- expect(actions_fetcher).to have_received(:fetch)
63
+ expect(SalsaLabs::ObjectsFetcher).to have_received(:fetch).
64
+ with(credentials: {email: 'foo@bar.com', password: 'pass'},
65
+ type: 'Action',
66
+ item_class: SalsaLabs::Action)
64
67
  end
65
68
  end
66
-
67
69
  end
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+
3
+ describe SalsaLabs::ObjectsFetcher do
4
+ let(:client) do
5
+ double(
6
+ 'API client',
7
+ fetch: File.read('spec/fixtures/getObjects.sjs_action.xml')
8
+ )
9
+ end
10
+
11
+ describe "#fetch" do
12
+ before(:each) do
13
+ allow(SalsaLabs::ApiClient).to receive(:new) { client }
14
+ end
15
+
16
+ it "calls the getObjects API endpoint" do
17
+ SalsaLabs::ObjectsFetcher.fetch(type: 'Action')
18
+
19
+ expect(client).to have_received(:fetch).
20
+ with('/api/getObjects.sjs', {object: 'Action'})
21
+ end
22
+
23
+ it "returns an array of SalsaLabs::Action objects" do
24
+ results = SalsaLabs::ObjectsFetcher.fetch(type: 'Action', item_class: SalsaLabs::Action)
25
+
26
+ expect(results).to be_a(Array)
27
+ expect(results.first).to be_a(SalsaLabs::Action)
28
+ end
29
+ end
30
+
31
+ it "parses actions" do
32
+ client = double('API Client', fetch: File.read('spec/fixtures/getObjects.sjs_action.xml'))
33
+ action = SalsaLabs::ObjectsFetcher.new(type: 'Action',
34
+ item_class: SalsaLabs::Action,
35
+ filters: {},
36
+ client: client).fetch.first
37
+
38
+ expect(action.action_key).to eq(6656)
39
+ expect(action.description).to eq("<p>&#160;</p>")
40
+ expect(action.title).to eq("My Action Title")
41
+ expect(action.reference_name).to eq("My TItle")
42
+ end
43
+
44
+ it "parses supporters" do
45
+ client = double('API Client', fetch: File.read('spec/fixtures/getObjects.sjs_supporter.xml'))
46
+ supporter = SalsaLabs::ObjectsFetcher.new(type: 'supporter',
47
+ item_class: SalsaLabs::Supporter,
48
+ filters: {},
49
+ client: client).fetch.first
50
+
51
+ expect(supporter.supporter_key).to eq(31752865)
52
+ expect(supporter.email).to eq("chris@example.com")
53
+ end
54
+
55
+ it "parses supporter actions" do
56
+ client = double('API Client', fetch: File.read('spec/fixtures/getObjects.sjs_supporter_actions.xml'))
57
+ supporter_action = SalsaLabs::ObjectsFetcher.new(type: 'supporter_action',
58
+ item_class: SalsaLabs::SupporterAction,
59
+ filters: {},
60
+ client: client).fetch.first
61
+
62
+ expect(supporter_action.supporter_action_key).to eq(898207)
63
+ expect(supporter_action.supporter_key).to eq(123)
64
+ expect(supporter_action.action_key).to eq(234)
65
+ end
66
+ end
@@ -12,7 +12,7 @@ describe SalsaLabs::SalsaObject do
12
12
  let(:salsa_object) { SalsaLabs::SalsaObject.new(attributes) }
13
13
 
14
14
  describe "#attributes" do
15
- it "returns the hash used to constuct the object" do
15
+ it "returns the hash used to construct the object" do
16
16
  expect(salsa_object.attributes).to eq(attributes)
17
17
  end
18
18
  end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe SalsaLabs::SupporterAction do
4
+ it "returns action_key" do
5
+ supporter_action = SalsaLabs::SupporterAction.new('action_key' => '123')
6
+
7
+ expect(supporter_action.action_key).to eq(123)
8
+ end
9
+
10
+ it "returns nil for nil action_key" do
11
+ supporter_action = SalsaLabs::SupporterAction.new({})
12
+
13
+ expect(supporter_action.action_key).to be_nil
14
+ end
15
+
16
+ it "returns supporter_key" do
17
+ supporter_action = SalsaLabs::SupporterAction.new('supporter_key' => '123')
18
+
19
+ expect(supporter_action.supporter_key).to eq(123)
20
+ end
21
+
22
+ it "returns nil for nil supporter_key" do
23
+ supporter_action = SalsaLabs::SupporterAction.new({})
24
+
25
+ expect(supporter_action.supporter_key).to be_nil
26
+ end
27
+
28
+ it "returns supporter_action_key" do
29
+ supporter_action = SalsaLabs::SupporterAction.new('supporter_action_key' => '123')
30
+
31
+ expect(supporter_action.supporter_action_key).to eq(123)
32
+ end
33
+
34
+ it "returns nil for nil supporter_action_key" do
35
+ supporter_action = SalsaLabs::SupporterAction.new({})
36
+
37
+ expect(supporter_action.supporter_action_key).to be_nil
38
+ end
39
+
40
+ describe ".fetch" do
41
+ it "fetches the supporter actions" do
42
+ SalsaLabs::ObjectsFetcher.stub(:fetch)
43
+
44
+ SalsaLabs::SupporterAction.fetch(email: "foo@bar.com",
45
+ password: "pass")
46
+
47
+ expect(SalsaLabs::ObjectsFetcher).to have_received(:fetch).with(
48
+ credentials: {email: "foo@bar.com", password: "pass"},
49
+ type: "supporter_action",
50
+ item_class: SalsaLabs::SupporterAction)
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe SalsaLabs::Supporter do
4
+ let(:supporter) { SalsaLabs::Supporter.new('email' => 'bob@example.com',
5
+ 'supporter_key' => '123') }
6
+
7
+ it "returns supporter's key" do
8
+ expect(supporter.supporter_key).to eq(123)
9
+ end
10
+
11
+ it "returns supporter's email" do
12
+ expect(supporter.email).to eq('bob@example.com')
13
+ end
14
+
15
+ describe ".fetch" do
16
+ it "passes the credentials to object fetcher" do
17
+ SalsaLabs::ObjectsFetcher.stub(:fetch)
18
+
19
+ SalsaLabs::Supporter.fetch(email: 'foo@bar.com', password: 'pass')
20
+
21
+ expect(SalsaLabs::ObjectsFetcher).to have_received(:fetch).with(
22
+ type: 'supporter',
23
+ item_class: SalsaLabs::Supporter,
24
+ credentials: {
25
+ email: 'foo@bar.com',
26
+ password: 'pass'
27
+ })
28
+ end
29
+ end
30
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: salsa_labs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2.alpha
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geoff Harcourt
@@ -9,118 +9,160 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-29 00:00:00.000000000 Z
12
+ date: 2014-04-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: dotenv
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ~>
19
19
  - !ruby/object:Gem::Version
20
20
  version: '0.9'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - "~>"
25
+ - - ~>
26
26
  - !ruby/object:Gem::Version
27
27
  version: '0.9'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: faraday
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - "~>"
32
+ - - ~>
33
33
  - !ruby/object:Gem::Version
34
34
  version: '0.8'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - "~>"
39
+ - - ~>
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0.8'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: httparty
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - "~>"
46
+ - - ~>
47
47
  - !ruby/object:Gem::Version
48
48
  version: '0.12'
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - "~>"
53
+ - - ~>
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0.12'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: nokogiri
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - "~>"
60
+ - - ~>
61
61
  - !ruby/object:Gem::Version
62
62
  version: '1.5'
63
63
  type: :runtime
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - "~>"
67
+ - - ~>
68
68
  - !ruby/object:Gem::Version
69
69
  version: '1.5'
70
+ - !ruby/object:Gem::Dependency
71
+ name: guard
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: guard-rspec
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: rake
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ~>
103
+ - !ruby/object:Gem::Version
104
+ version: 10.1.1
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ~>
110
+ - !ruby/object:Gem::Version
111
+ version: 10.1.1
70
112
  - !ruby/object:Gem::Dependency
71
113
  name: rspec
72
114
  requirement: !ruby/object:Gem::Requirement
73
115
  requirements:
74
- - - "~>"
116
+ - - ~>
75
117
  - !ruby/object:Gem::Version
76
118
  version: '2.14'
77
119
  type: :development
78
120
  prerelease: false
79
121
  version_requirements: !ruby/object:Gem::Requirement
80
122
  requirements:
81
- - - "~>"
123
+ - - ~>
82
124
  - !ruby/object:Gem::Version
83
125
  version: '2.14'
84
126
  - !ruby/object:Gem::Dependency
85
127
  name: simplecov
86
128
  requirement: !ruby/object:Gem::Requirement
87
129
  requirements:
88
- - - "~>"
130
+ - - ~>
89
131
  - !ruby/object:Gem::Version
90
132
  version: '0.8'
91
133
  type: :development
92
134
  prerelease: false
93
135
  version_requirements: !ruby/object:Gem::Requirement
94
136
  requirements:
95
- - - "~>"
137
+ - - ~>
96
138
  - !ruby/object:Gem::Version
97
139
  version: '0.8'
98
140
  - !ruby/object:Gem::Dependency
99
141
  name: vcr
100
142
  requirement: !ruby/object:Gem::Requirement
101
143
  requirements:
102
- - - "~>"
144
+ - - ~>
103
145
  - !ruby/object:Gem::Version
104
146
  version: '2.8'
105
147
  type: :development
106
148
  prerelease: false
107
149
  version_requirements: !ruby/object:Gem::Requirement
108
150
  requirements:
109
- - - "~>"
151
+ - - ~>
110
152
  - !ruby/object:Gem::Version
111
153
  version: '2.8'
112
154
  - !ruby/object:Gem::Dependency
113
155
  name: webmock
114
156
  requirement: !ruby/object:Gem::Requirement
115
157
  requirements:
116
- - - "~>"
158
+ - - ~>
117
159
  - !ruby/object:Gem::Version
118
160
  version: '1.16'
119
161
  type: :development
120
162
  prerelease: false
121
163
  version_requirements: !ruby/object:Gem::Requirement
122
164
  requirements:
123
- - - "~>"
165
+ - - ~>
124
166
  - !ruby/object:Gem::Version
125
167
  version: '1.16'
126
168
  description: A Ruby binding for the Salsa Labs (http://salsalabs.com) API.
@@ -130,25 +172,35 @@ executables: []
130
172
  extensions: []
131
173
  extra_rdoc_files: []
132
174
  files:
133
- - ".gitignore"
134
- - ".travis.yml"
175
+ - .gitignore
176
+ - .rspec
177
+ - .ruby-gemset
178
+ - .ruby-version
179
+ - .travis.yml
135
180
  - Gemfile
136
181
  - Gemfile.lock
182
+ - Guardfile
137
183
  - LICENSE
138
184
  - README.md
139
185
  - Rakefile
140
186
  - lib/salsa_labs.rb
141
187
  - lib/salsa_labs/action.rb
142
- - lib/salsa_labs/actions_fetcher.rb
143
188
  - lib/salsa_labs/api_client.rb
189
+ - lib/salsa_labs/objects_fetcher.rb
144
190
  - lib/salsa_labs/salsa_object.rb
191
+ - lib/salsa_labs/supporter.rb
192
+ - lib/salsa_labs/supporter_action.rb
145
193
  - lib/salsa_labs/version.rb
146
194
  - salsa_labs.gemspec
147
195
  - spec/fixtures/getObjects.sjs_action.xml
196
+ - spec/fixtures/getObjects.sjs_supporter.xml
197
+ - spec/fixtures/getObjects.sjs_supporter_actions.xml
148
198
  - spec/salsa_labs/action_spec.rb
149
- - spec/salsa_labs/actions_fetcher_spec.rb
150
199
  - spec/salsa_labs/api_client_spec.rb
200
+ - spec/salsa_labs/objects_fetcher_spec.rb
151
201
  - spec/salsa_labs/salsa_object_spec.rb
202
+ - spec/salsa_labs/supporter_action_spec.rb
203
+ - spec/salsa_labs/supporter_spec.rb
152
204
  - spec/spec_helper.rb
153
205
  - spec/vcr_cassettes/get_objects/action.yml
154
206
  - spec/vcr_cassettes/successful_authentication.yml
@@ -163,27 +215,31 @@ require_paths:
163
215
  - lib
164
216
  required_ruby_version: !ruby/object:Gem::Requirement
165
217
  requirements:
166
- - - ">="
218
+ - - '>='
167
219
  - !ruby/object:Gem::Version
168
220
  version: '0'
169
221
  required_rubygems_version: !ruby/object:Gem::Requirement
170
222
  requirements:
171
- - - ">"
223
+ - - '>='
172
224
  - !ruby/object:Gem::Version
173
- version: 1.3.1
225
+ version: '0'
174
226
  requirements: []
175
227
  rubyforge_project:
176
- rubygems_version: 2.2.0
228
+ rubygems_version: 2.0.14
177
229
  signing_key:
178
230
  specification_version: 4
179
231
  summary: Salsa Labs' API contains information about supporters, donations, and actions.
180
232
  This gem faciliates pulling that information into a Ruby application.
181
233
  test_files:
182
234
  - spec/fixtures/getObjects.sjs_action.xml
235
+ - spec/fixtures/getObjects.sjs_supporter.xml
236
+ - spec/fixtures/getObjects.sjs_supporter_actions.xml
183
237
  - spec/salsa_labs/action_spec.rb
184
- - spec/salsa_labs/actions_fetcher_spec.rb
185
238
  - spec/salsa_labs/api_client_spec.rb
239
+ - spec/salsa_labs/objects_fetcher_spec.rb
186
240
  - spec/salsa_labs/salsa_object_spec.rb
241
+ - spec/salsa_labs/supporter_action_spec.rb
242
+ - spec/salsa_labs/supporter_spec.rb
187
243
  - spec/spec_helper.rb
188
244
  - spec/vcr_cassettes/get_objects/action.yml
189
245
  - spec/vcr_cassettes/successful_authentication.yml
@@ -1,61 +0,0 @@
1
- module SalsaLabs
2
- ##
3
- # Service object to pull back a collection of actions from the Salsa Labs API.
4
- ##
5
- class ActionsFetcher
6
-
7
- def initialize(filter_parameters = {}, credentials = {})
8
- @filter_parameters = filter_parameters
9
- @client = SalsaLabs::ApiClient.new(credentials)
10
- end
11
-
12
- def fetch
13
- item_nodes.map do |node|
14
- SalsaLabs::Action.new(SalsaLabsApiObjectNode.new(node).attributes)
15
- end
16
- end
17
-
18
- private
19
-
20
- attr_reader :client, :filter_parameters
21
-
22
- def api_call
23
- client.fetch('/api/getObjects.sjs', api_parameters)
24
- end
25
-
26
- def api_parameters
27
- filter_parameters.merge(object: 'Action')
28
- end
29
-
30
- def item_nodes
31
- Nokogiri::XML(api_call).css('item')
32
- end
33
-
34
- ##
35
- # Object used to translate API's XML node into a hash of attributes for
36
- # SalsaLabs::Action creation.
37
- ##
38
- class SalsaLabsApiObjectNode
39
-
40
- def initialize(xml_element)
41
- @node = xml_element
42
- end
43
-
44
- def attributes
45
- children.inject({}) do |memo, attribute|
46
- memo[attribute.name.downcase] = attribute.text
47
- attribute
48
- end
49
- end
50
-
51
- private
52
-
53
- attr_reader :node
54
-
55
- def children
56
- node.children
57
- end
58
-
59
- end
60
- end
61
- end
@@ -1,32 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe SalsaLabs::ActionsFetcher do
4
-
5
- let(:client) do
6
- double(
7
- 'API client',
8
- fetch: File.read('spec/fixtures/getObjects.sjs_action.xml')
9
- )
10
- end
11
-
12
- describe "#fetch" do
13
- before(:each) do
14
- allow(SalsaLabs::ApiClient).to receive(:new) { client }
15
- end
16
-
17
- it "calls the getObjects API endpoint" do
18
- SalsaLabs::ActionsFetcher.new.fetch
19
-
20
- expect(client).to have_received(:fetch).
21
- with('/api/getObjects.sjs', {object: 'Action'})
22
- end
23
-
24
- it "returns an array of SalsaLabs::Action objects" do
25
- results = SalsaLabs::ActionsFetcher.new.fetch
26
-
27
- expect(results).to be_a(Array)
28
- expect(results.first).to be_a(SalsaLabs::Action)
29
- end
30
- end
31
-
32
- end