agra_api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0745e090bc629c9347b35fd8ec0ce7528b0395fd
4
+ data.tar.gz: 8009926a5a599a4c2e1577927c2187f4d2fcdec7
5
+ SHA512:
6
+ metadata.gz: 9c58406030bb2a12613dbec0f9173250d322f50326a098dd4e19407392176d73db8abec264f64d55d517e73732e46a07983d4ed3ad3d916a969a0e31d51ee7f0
7
+ data.tar.gz: d1690264adbeddceb480e24f9833773ff3abceab29a572fc39ae2cf42e72f7e6d78347cfda6e592acf494578764c708d99e07e22355ab5e5119b54a00aa9d178
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1 @@
1
+ agra_api
@@ -0,0 +1 @@
1
+ ruby-2.0.0-p247
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ gemspec
3
+
4
+ # Add dependencies to develop your gem here.
5
+ # Include everything needed to run rake, tests, features, etc.
6
+ group :development do
7
+ gem "rspec"
8
+ gem 'webmock'
9
+ gem 'pry'
10
+ gem 'pry-debugger'
11
+ gem "bundler"
12
+ gem "jeweler", "~> 1.8.4"
13
+ end
@@ -0,0 +1,115 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ agra_api (0.1.0)
5
+ agra_api
6
+ vertebrae
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ activesupport (4.0.0)
12
+ i18n (~> 0.6, >= 0.6.4)
13
+ minitest (~> 4.2)
14
+ multi_json (~> 1.3)
15
+ thread_safe (~> 0.1)
16
+ tzinfo (~> 0.3.37)
17
+ addressable (2.3.5)
18
+ atomic (1.1.14)
19
+ builder (3.2.2)
20
+ coderay (1.0.9)
21
+ columnize (0.3.6)
22
+ crack (0.4.1)
23
+ safe_yaml (~> 0.9.0)
24
+ debugger (1.6.2)
25
+ columnize (>= 0.3.1)
26
+ debugger-linecache (~> 1.2.0)
27
+ debugger-ruby_core_source (~> 1.2.3)
28
+ debugger-linecache (1.2.0)
29
+ debugger-ruby_core_source (1.2.3)
30
+ diff-lcs (1.2.4)
31
+ faraday (0.8.8)
32
+ multipart-post (~> 1.2.0)
33
+ faraday_middleware (0.9.0)
34
+ faraday (>= 0.7.4, < 0.9)
35
+ git (1.2.6)
36
+ github_api (0.10.1)
37
+ addressable
38
+ faraday (~> 0.8.1)
39
+ hashie (>= 1.2)
40
+ multi_json (~> 1.4)
41
+ nokogiri (~> 1.5.2)
42
+ oauth2
43
+ hashie (2.0.5)
44
+ highline (1.6.20)
45
+ httpauth (0.2.0)
46
+ i18n (0.6.5)
47
+ jeweler (1.8.8)
48
+ builder
49
+ bundler (~> 1.0)
50
+ git (>= 1.2.5)
51
+ github_api (= 0.10.1)
52
+ highline (>= 1.6.15)
53
+ nokogiri (= 1.5.10)
54
+ rake
55
+ rdoc
56
+ json (1.8.1)
57
+ jwt (0.1.8)
58
+ multi_json (>= 1.5)
59
+ method_source (0.8.2)
60
+ minitest (4.7.5)
61
+ multi_json (1.8.2)
62
+ multi_xml (0.5.5)
63
+ multipart-post (1.2.0)
64
+ nokogiri (1.5.10)
65
+ oauth2 (0.9.2)
66
+ faraday (~> 0.8)
67
+ httpauth (~> 0.2)
68
+ jwt (~> 0.1.4)
69
+ multi_json (~> 1.0)
70
+ multi_xml (~> 0.5)
71
+ rack (~> 1.2)
72
+ pry (0.9.12.2)
73
+ coderay (~> 1.0.5)
74
+ method_source (~> 0.8)
75
+ slop (~> 3.4)
76
+ pry-debugger (0.2.2)
77
+ debugger (~> 1.3)
78
+ pry (~> 0.9.10)
79
+ rack (1.5.2)
80
+ rake (10.1.0)
81
+ rdoc (4.0.1)
82
+ json (~> 1.4)
83
+ rspec (2.14.1)
84
+ rspec-core (~> 2.14.0)
85
+ rspec-expectations (~> 2.14.0)
86
+ rspec-mocks (~> 2.14.0)
87
+ rspec-core (2.14.6)
88
+ rspec-expectations (2.14.3)
89
+ diff-lcs (>= 1.1.3, < 2.0)
90
+ rspec-mocks (2.14.4)
91
+ safe_yaml (0.9.7)
92
+ slop (3.4.6)
93
+ thread_safe (0.1.3)
94
+ atomic
95
+ tzinfo (0.3.38)
96
+ vertebrae (0.2.2)
97
+ activesupport
98
+ faraday
99
+ faraday_middleware
100
+ hashie
101
+ webmock (1.15.0)
102
+ addressable (>= 2.2.7)
103
+ crack (>= 0.3.2)
104
+
105
+ PLATFORMS
106
+ ruby
107
+
108
+ DEPENDENCIES
109
+ agra_api!
110
+ bundler
111
+ jeweler (~> 1.8.4)
112
+ pry
113
+ pry-debugger
114
+ rspec
115
+ webmock
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 ControlShift Ltd.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,13 @@
1
+ = agra_api
2
+
3
+ A ruby gem for communicating with ControlShift's Agra API.
4
+
5
+ == Usage
6
+
7
+ To be determined.
8
+
9
+ == Copyright
10
+
11
+ Copyright (c) 2013 Nathan Woodhull. See LICENSE.txt for
12
+ further details.
13
+
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require './lib/agra_api/version.rb'
15
+
16
+ require 'jeweler'
17
+ Jeweler::Tasks.new do |gem|
18
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
19
+ gem.name = "agra_api"
20
+ gem.version = AgraApi::VERSION::STRING
21
+ gem.homepage = "http://github.com/controlshift/agra_api"
22
+ gem.license = "MIT"
23
+ gem.summary = "A very basic agra client gem"
24
+ gem.description = "Agra is a distributed petitions platform, this is a gem for talking to it's API"
25
+ gem.email = "nathan@controlshiftlabs.com"
26
+ gem.authors = ["Nathan Woodhull"]
27
+ # dependencies defined in Gemfile
28
+ gem.add_dependency 'vertebrae'
29
+ end
30
+ Jeweler::RubygemsDotOrgTasks.new
31
+
32
+ require 'rspec/core'
33
+ require 'rspec/core/rake_task'
34
+ RSpec::Core::RakeTask.new(:spec) do |spec|
35
+ spec.pattern = FileList['spec/**/*_spec.rb']
36
+ end
37
+
38
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
39
+ spec.pattern = 'spec/**/*_spec.rb'
40
+ spec.rcov = true
41
+ end
42
+
43
+ task :default => :spec
44
+
45
+ require 'rdoc/task'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "agra_api #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
@@ -0,0 +1,134 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "agra_api"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Nathan Woodhull"]
12
+ s.date = "2013-10-27"
13
+ s.description = "Agra is a distributed petitions platform, this is a gem for talking to it's API"
14
+ s.email = "nathan@controlshiftlabs.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ ".ruby-gemset",
23
+ ".ruby-version",
24
+ "Gemfile",
25
+ "Gemfile.lock",
26
+ "LICENSE.txt",
27
+ "README.rdoc",
28
+ "Rakefile",
29
+ "agra_api.gemspec",
30
+ "lib/agra_api.rb",
31
+ "lib/agra_api/base.rb",
32
+ "lib/agra_api/client.rb",
33
+ "lib/agra_api/organisation.rb",
34
+ "lib/agra_api/version.rb",
35
+ "spec/agra_api_spec.rb",
36
+ "spec/client_spec.rb",
37
+ "spec/fixtures/organisation",
38
+ "spec/organisation_spec.rb",
39
+ "spec/spec_helper.rb"
40
+ ]
41
+ s.homepage = "http://github.com/controlshift/agra_api"
42
+ s.licenses = ["MIT"]
43
+ s.require_paths = ["lib"]
44
+ s.rubygems_version = "2.0.7"
45
+ s.summary = "A very basic agra client gem"
46
+
47
+ if s.respond_to? :specification_version then
48
+ s.specification_version = 4
49
+
50
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
51
+ s.add_runtime_dependency(%q<agra_api>, [">= 0"])
52
+ s.add_development_dependency(%q<rspec>, [">= 0"])
53
+ s.add_development_dependency(%q<webmock>, [">= 0"])
54
+ s.add_development_dependency(%q<pry>, [">= 0"])
55
+ s.add_development_dependency(%q<pry-debugger>, [">= 0"])
56
+ s.add_development_dependency(%q<bundler>, [">= 0"])
57
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
58
+ s.add_development_dependency(%q<rspec>, [">= 0"])
59
+ s.add_development_dependency(%q<webmock>, [">= 0"])
60
+ s.add_development_dependency(%q<pry>, [">= 0"])
61
+ s.add_development_dependency(%q<pry-debugger>, [">= 0"])
62
+ s.add_development_dependency(%q<bundler>, [">= 0"])
63
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
64
+ s.add_development_dependency(%q<rspec>, [">= 0"])
65
+ s.add_development_dependency(%q<webmock>, [">= 0"])
66
+ s.add_development_dependency(%q<pry>, [">= 0"])
67
+ s.add_development_dependency(%q<pry-debugger>, [">= 0"])
68
+ s.add_development_dependency(%q<bundler>, [">= 0"])
69
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
70
+ s.add_development_dependency(%q<rspec>, [">= 0"])
71
+ s.add_development_dependency(%q<webmock>, [">= 0"])
72
+ s.add_development_dependency(%q<pry>, [">= 0"])
73
+ s.add_development_dependency(%q<pry-debugger>, [">= 0"])
74
+ s.add_development_dependency(%q<bundler>, [">= 0"])
75
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
76
+ s.add_runtime_dependency(%q<vertebrae>, [">= 0"])
77
+ else
78
+ s.add_dependency(%q<agra_api>, [">= 0"])
79
+ s.add_dependency(%q<rspec>, [">= 0"])
80
+ s.add_dependency(%q<webmock>, [">= 0"])
81
+ s.add_dependency(%q<pry>, [">= 0"])
82
+ s.add_dependency(%q<pry-debugger>, [">= 0"])
83
+ s.add_dependency(%q<bundler>, [">= 0"])
84
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
85
+ s.add_dependency(%q<rspec>, [">= 0"])
86
+ s.add_dependency(%q<webmock>, [">= 0"])
87
+ s.add_dependency(%q<pry>, [">= 0"])
88
+ s.add_dependency(%q<pry-debugger>, [">= 0"])
89
+ s.add_dependency(%q<bundler>, [">= 0"])
90
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
91
+ s.add_dependency(%q<rspec>, [">= 0"])
92
+ s.add_dependency(%q<webmock>, [">= 0"])
93
+ s.add_dependency(%q<pry>, [">= 0"])
94
+ s.add_dependency(%q<pry-debugger>, [">= 0"])
95
+ s.add_dependency(%q<bundler>, [">= 0"])
96
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
97
+ s.add_dependency(%q<rspec>, [">= 0"])
98
+ s.add_dependency(%q<webmock>, [">= 0"])
99
+ s.add_dependency(%q<pry>, [">= 0"])
100
+ s.add_dependency(%q<pry-debugger>, [">= 0"])
101
+ s.add_dependency(%q<bundler>, [">= 0"])
102
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
103
+ s.add_dependency(%q<vertebrae>, [">= 0"])
104
+ end
105
+ else
106
+ s.add_dependency(%q<agra_api>, [">= 0"])
107
+ s.add_dependency(%q<rspec>, [">= 0"])
108
+ s.add_dependency(%q<webmock>, [">= 0"])
109
+ s.add_dependency(%q<pry>, [">= 0"])
110
+ s.add_dependency(%q<pry-debugger>, [">= 0"])
111
+ s.add_dependency(%q<bundler>, [">= 0"])
112
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
113
+ s.add_dependency(%q<rspec>, [">= 0"])
114
+ s.add_dependency(%q<webmock>, [">= 0"])
115
+ s.add_dependency(%q<pry>, [">= 0"])
116
+ s.add_dependency(%q<pry-debugger>, [">= 0"])
117
+ s.add_dependency(%q<bundler>, [">= 0"])
118
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
119
+ s.add_dependency(%q<rspec>, [">= 0"])
120
+ s.add_dependency(%q<webmock>, [">= 0"])
121
+ s.add_dependency(%q<pry>, [">= 0"])
122
+ s.add_dependency(%q<pry-debugger>, [">= 0"])
123
+ s.add_dependency(%q<bundler>, [">= 0"])
124
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
125
+ s.add_dependency(%q<rspec>, [">= 0"])
126
+ s.add_dependency(%q<webmock>, [">= 0"])
127
+ s.add_dependency(%q<pry>, [">= 0"])
128
+ s.add_dependency(%q<pry-debugger>, [">= 0"])
129
+ s.add_dependency(%q<bundler>, [">= 0"])
130
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
131
+ s.add_dependency(%q<vertebrae>, [">= 0"])
132
+ end
133
+ end
134
+
@@ -0,0 +1,14 @@
1
+ require 'vertebrae'
2
+ require 'agra_api/base'
3
+ require 'agra_api/organisation'
4
+ require 'agra_api/client'
5
+
6
+ module AgraApi
7
+ extend Vertebrae::Base
8
+
9
+ class << self
10
+ def new(options = {}, &block)
11
+ AgraApi::Client.new(options, &block)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,7 @@
1
+ module AgraApi
2
+ class Base < Vertebrae::Model
3
+ def normalized_base_path
4
+ "api/#{base_path}/"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,52 @@
1
+ module AgraApi
2
+ class Client < Vertebrae::API
3
+ def organisation
4
+ @user ||= AgraApi::Organisation.new(client: self)
5
+ end
6
+
7
+ def default_options
8
+ {
9
+ user_agent: 'AgraApi Gem',
10
+ prefix: '',
11
+ content_type: 'application/json'
12
+ }
13
+ end
14
+
15
+ def request(method, path, params, options) # :nodoc:
16
+ if !::Vertebrae::Request::METHODS.include?(method)
17
+ raise ArgumentError, "unknown http method: #{method}"
18
+ end
19
+
20
+ path = connection.configuration.prefix + '/' + path
21
+
22
+ ::Vertebrae::Base.logger.debug "EXECUTED: #{method} - #{path} with #{params} and #{options}"
23
+
24
+ connection.connection.send(method) do |request|
25
+
26
+ case method.to_sym
27
+ when *(::Vertebrae::Request::METHODS - ::Vertebrae::Request::METHODS_WITH_BODIES)
28
+ request.url(path, params)
29
+ when *::Vertebrae::Request::METHODS_WITH_BODIES
30
+ request.path = path
31
+ request.body = extract_data_from_params(params) unless params.empty?
32
+ end
33
+ end
34
+ end
35
+
36
+ def setup
37
+ connection.stack do |builder|
38
+ builder.use Faraday::Request::Multipart
39
+ builder.use Faraday::Request::UrlEncoded
40
+ builder.use Vertebrae::Request::BasicAuth, connection.configuration.authentication if connection.configuration.authenticated?
41
+
42
+ builder.use Faraday::Response::Logger if ENV['DEBUG']
43
+
44
+ builder.use FaradayMiddleware::Mashify
45
+ builder.use FaradayMiddleware::ParseJson
46
+
47
+ builder.use Vertebrae::Response::RaiseError
48
+ builder.adapter connection.configuration.adapter
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,12 @@
1
+ module AgraApi
2
+ class Organisation < Base
3
+ def base_path
4
+ 'organisations'
5
+ end
6
+
7
+ def find_by_host(host)
8
+ response = client.get_request(normalized_base_path, host: host)
9
+ response.body
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ module AgraApi
2
+ module VERSION
3
+ MAJOR = 0
4
+ MINOR = 1
5
+ PATCH = 0
6
+ BUILD = nil
7
+
8
+ STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe AgraApi do
4
+ before(:each) do
5
+ AgraApi::Client.stub(:setup_client)
6
+ end
7
+ specify { subject.should respond_to :organisation }
8
+ specify { subject.new.should be_a(AgraApi::Client)}
9
+ end
10
+
11
+
@@ -0,0 +1,16 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe AgraApi::Client do
4
+
5
+ describe "instantiated" do
6
+ subject { described_class.new(options) }
7
+
8
+ context 'process_basic_auth' do
9
+ let(:options) { { :basic_auth => 'login:password' } }
10
+ let(:config) { subject.connection.configuration }
11
+ specify { config.username.should eq 'login' }
12
+ specify { config.password.should eq 'password' }
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1 @@
1
+ {"admin_email":"info@controlshiftlabs.com","blog_link":"","campaigner_feedback_link":"","contact_email":"info@controlshiftlabs.com","created_at":"2013-04-15T13:31:49-04:00","facebook_url":"","google_analytics_tracking_id":"","host":"localhost","id":1,"name":"Default Org","parent_name":"","parent_url":"","placeholder_content_type":null,"placeholder_file_name":null,"placeholder_file_size":null,"placeholder_updated_at":null,"preferred_locale":"en","sendgrid_password":null,"sendgrid_username":null,"settings":{"show_petition_category_on_creation":"0","requires_user_confirmation_on_sign_up":"0","requires_location_for_campaign":"1","always_join_parent_org_when_sign_up":"0","hide_signatures_csv_download_link":"0","hide_phone_number_on_signature_form":"0","show_categories_as_dropdown":"0","list_petitions_under_map":"0","expose_broadcast_emails":"1","home_link_override":"","signature_disclaimer":"","new_account_disclaimer":"","join_label":"","country":"","google_maps_key":"","enable_facebook_login":"1","fb_app_id":"bar","fb_app_secret":"foo","notifiers":"actionkit","bsd_host":"","bsd_api_id":"","bsd_api_secret":"","salesforce_host":"","salesforce_consumer_key":"","salesforce_consumer_secret":"","salesforce_username":"","salesforce_security_token":"","action_kit_host":"foo.com","action_kit_username":"bar","action_kit_password":"foo","action_kit_country":"","action_kit_signature_page":"","action_kit_petition_page":"","long_name":"long name","phone_number_not_mandatory_on_registration":"0","action_kit_tag_id":[1,4],"action_kit_tag_ids":[[1,4]],"preferred_language":"en","tijuana_host":"test","tijuana_username":"test","tijuana_password":"test","supported_languages":["en"],"signature_fields_override":"","purpose_host":"host","purpose_username":"usern","purpose_password":"pass","purpose_movement_id":"movement"},"slug":"gsanetwork","time_zone":"Eastern Time (US & Canada)","twitter_account_name":"","updated_at":"2013-10-18T14:43:03-04:00","user_feedback_link":"","uservoice_widget_link":""}
@@ -0,0 +1,58 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe AgraApi::Organisation do
4
+ subject { AgraApi.new(host: 'test.com') }
5
+
6
+ describe 'configuration' do
7
+ it 'should propagate the host' do
8
+ subject.organisation.client.connection.configuration.host.should == 'test.com'
9
+ end
10
+ end
11
+
12
+ describe 'find_by_host' do
13
+ let(:body) { fixture('organisation') }
14
+ let(:request_path) { '/api/organisations/?host=foo.com' }
15
+
16
+ before(:each) do
17
+ stub_get(request_path).to_return(:body => body, :status => status,
18
+ :headers => { content_type: "application/json; charset=utf-8"})
19
+ end
20
+
21
+ describe 'success' do
22
+ let(:status) { 200 }
23
+ let(:organisation) { subject.organisation.find_by_host('foo.com') }
24
+
25
+ it 'should find an organisation' do
26
+ organisation.settings.action_kit_host.should == 'foo.com'
27
+ end
28
+ end
29
+
30
+ describe 'an error' do
31
+ let(:status) { 500 }
32
+
33
+ it 'should raise' do
34
+ lambda { subject.organisation.find_by_host('foo.com') }.should raise_exception
35
+ end
36
+ end
37
+ end
38
+
39
+ describe "basic authentication" do
40
+ subject { AgraApi.new(host: 'test.com', username: 'username', password: 'password')}
41
+ let(:request_path) { '/api/organisations/?host=foo.com' }
42
+ let(:body) { "" }
43
+
44
+ before(:each) do
45
+ stub_request(:get, "https://username:password@test.com#{request_path}").to_return(:body => body, :status => status,
46
+ :headers => { content_type: "application/json; charset=utf-8"})
47
+ end
48
+
49
+
50
+ describe "unauthorized" do
51
+ let(:status) { 401 }
52
+
53
+ it "should raise" do
54
+ lambda { subject.organisation.find_by_host('foo.com') }.should raise_exception
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,48 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'webmock'
5
+ require 'agra_api'
6
+
7
+
8
+ # Requires supporting files with custom matchers and macros, etc,
9
+ # in ./support/ and its subdirectories.
10
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
11
+
12
+
13
+ RSpec.configure do |config|
14
+ config.include WebMock::API
15
+ config.color_enabled = true
16
+
17
+
18
+ config.before(:each) do
19
+ WebMock.reset!
20
+ end
21
+ config.after(:each) do
22
+ WebMock.reset!
23
+ end
24
+
25
+ end
26
+
27
+ def stub_get(path)
28
+ stub_agra_request(:get, path)
29
+ end
30
+
31
+ def stub_post(path)
32
+ stub_agra_request(:post, path)
33
+ end
34
+
35
+ def stub_agra_request(method, path)
36
+ prefix = AgraApi.new.connection.configuration.prefix.to_s
37
+ stub_request(method, "https://test.com" + prefix + path)
38
+ end
39
+
40
+
41
+
42
+ def fixture_path
43
+ File.expand_path("../fixtures", __FILE__)
44
+ end
45
+
46
+ def fixture(file)
47
+ File.new(File.join(fixture_path, '/', file))
48
+ end
metadata ADDED
@@ -0,0 +1,430 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: agra_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nathan Woodhull
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: agra_api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: webmock
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-debugger
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: jeweler
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: 1.8.4
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: 1.8.4
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: webmock
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: pry
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: pry-debugger
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: bundler
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - '>='
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: jeweler
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ~>
186
+ - !ruby/object:Gem::Version
187
+ version: 1.8.4
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ~>
193
+ - !ruby/object:Gem::Version
194
+ version: 1.8.4
195
+ - !ruby/object:Gem::Dependency
196
+ name: rspec
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - '>='
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - '>='
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: webmock
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - '>='
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - '>='
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
223
+ - !ruby/object:Gem::Dependency
224
+ name: pry
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - '>='
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - '>='
235
+ - !ruby/object:Gem::Version
236
+ version: '0'
237
+ - !ruby/object:Gem::Dependency
238
+ name: pry-debugger
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - '>='
242
+ - !ruby/object:Gem::Version
243
+ version: '0'
244
+ type: :development
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - '>='
249
+ - !ruby/object:Gem::Version
250
+ version: '0'
251
+ - !ruby/object:Gem::Dependency
252
+ name: bundler
253
+ requirement: !ruby/object:Gem::Requirement
254
+ requirements:
255
+ - - '>='
256
+ - !ruby/object:Gem::Version
257
+ version: '0'
258
+ type: :development
259
+ prerelease: false
260
+ version_requirements: !ruby/object:Gem::Requirement
261
+ requirements:
262
+ - - '>='
263
+ - !ruby/object:Gem::Version
264
+ version: '0'
265
+ - !ruby/object:Gem::Dependency
266
+ name: jeweler
267
+ requirement: !ruby/object:Gem::Requirement
268
+ requirements:
269
+ - - ~>
270
+ - !ruby/object:Gem::Version
271
+ version: 1.8.4
272
+ type: :development
273
+ prerelease: false
274
+ version_requirements: !ruby/object:Gem::Requirement
275
+ requirements:
276
+ - - ~>
277
+ - !ruby/object:Gem::Version
278
+ version: 1.8.4
279
+ - !ruby/object:Gem::Dependency
280
+ name: rspec
281
+ requirement: !ruby/object:Gem::Requirement
282
+ requirements:
283
+ - - '>='
284
+ - !ruby/object:Gem::Version
285
+ version: '0'
286
+ type: :development
287
+ prerelease: false
288
+ version_requirements: !ruby/object:Gem::Requirement
289
+ requirements:
290
+ - - '>='
291
+ - !ruby/object:Gem::Version
292
+ version: '0'
293
+ - !ruby/object:Gem::Dependency
294
+ name: webmock
295
+ requirement: !ruby/object:Gem::Requirement
296
+ requirements:
297
+ - - '>='
298
+ - !ruby/object:Gem::Version
299
+ version: '0'
300
+ type: :development
301
+ prerelease: false
302
+ version_requirements: !ruby/object:Gem::Requirement
303
+ requirements:
304
+ - - '>='
305
+ - !ruby/object:Gem::Version
306
+ version: '0'
307
+ - !ruby/object:Gem::Dependency
308
+ name: pry
309
+ requirement: !ruby/object:Gem::Requirement
310
+ requirements:
311
+ - - '>='
312
+ - !ruby/object:Gem::Version
313
+ version: '0'
314
+ type: :development
315
+ prerelease: false
316
+ version_requirements: !ruby/object:Gem::Requirement
317
+ requirements:
318
+ - - '>='
319
+ - !ruby/object:Gem::Version
320
+ version: '0'
321
+ - !ruby/object:Gem::Dependency
322
+ name: pry-debugger
323
+ requirement: !ruby/object:Gem::Requirement
324
+ requirements:
325
+ - - '>='
326
+ - !ruby/object:Gem::Version
327
+ version: '0'
328
+ type: :development
329
+ prerelease: false
330
+ version_requirements: !ruby/object:Gem::Requirement
331
+ requirements:
332
+ - - '>='
333
+ - !ruby/object:Gem::Version
334
+ version: '0'
335
+ - !ruby/object:Gem::Dependency
336
+ name: bundler
337
+ requirement: !ruby/object:Gem::Requirement
338
+ requirements:
339
+ - - '>='
340
+ - !ruby/object:Gem::Version
341
+ version: '0'
342
+ type: :development
343
+ prerelease: false
344
+ version_requirements: !ruby/object:Gem::Requirement
345
+ requirements:
346
+ - - '>='
347
+ - !ruby/object:Gem::Version
348
+ version: '0'
349
+ - !ruby/object:Gem::Dependency
350
+ name: jeweler
351
+ requirement: !ruby/object:Gem::Requirement
352
+ requirements:
353
+ - - ~>
354
+ - !ruby/object:Gem::Version
355
+ version: 1.8.4
356
+ type: :development
357
+ prerelease: false
358
+ version_requirements: !ruby/object:Gem::Requirement
359
+ requirements:
360
+ - - ~>
361
+ - !ruby/object:Gem::Version
362
+ version: 1.8.4
363
+ - !ruby/object:Gem::Dependency
364
+ name: vertebrae
365
+ requirement: !ruby/object:Gem::Requirement
366
+ requirements:
367
+ - - '>='
368
+ - !ruby/object:Gem::Version
369
+ version: '0'
370
+ type: :runtime
371
+ prerelease: false
372
+ version_requirements: !ruby/object:Gem::Requirement
373
+ requirements:
374
+ - - '>='
375
+ - !ruby/object:Gem::Version
376
+ version: '0'
377
+ description: Agra is a distributed petitions platform, this is a gem for talking to
378
+ it's API
379
+ email: nathan@controlshiftlabs.com
380
+ executables: []
381
+ extensions: []
382
+ extra_rdoc_files:
383
+ - LICENSE.txt
384
+ - README.rdoc
385
+ files:
386
+ - .document
387
+ - .rspec
388
+ - .ruby-gemset
389
+ - .ruby-version
390
+ - Gemfile
391
+ - Gemfile.lock
392
+ - LICENSE.txt
393
+ - README.rdoc
394
+ - Rakefile
395
+ - agra_api.gemspec
396
+ - lib/agra_api.rb
397
+ - lib/agra_api/base.rb
398
+ - lib/agra_api/client.rb
399
+ - lib/agra_api/organisation.rb
400
+ - lib/agra_api/version.rb
401
+ - spec/agra_api_spec.rb
402
+ - spec/client_spec.rb
403
+ - spec/fixtures/organisation
404
+ - spec/organisation_spec.rb
405
+ - spec/spec_helper.rb
406
+ homepage: http://github.com/controlshift/agra_api
407
+ licenses:
408
+ - MIT
409
+ metadata: {}
410
+ post_install_message:
411
+ rdoc_options: []
412
+ require_paths:
413
+ - lib
414
+ required_ruby_version: !ruby/object:Gem::Requirement
415
+ requirements:
416
+ - - '>='
417
+ - !ruby/object:Gem::Version
418
+ version: '0'
419
+ required_rubygems_version: !ruby/object:Gem::Requirement
420
+ requirements:
421
+ - - '>='
422
+ - !ruby/object:Gem::Version
423
+ version: '0'
424
+ requirements: []
425
+ rubyforge_project:
426
+ rubygems_version: 2.0.7
427
+ signing_key:
428
+ specification_version: 4
429
+ summary: A very basic agra client gem
430
+ test_files: []