planning_center 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. checksums.yaml +7 -0
  2. data/.env +4 -0
  3. data/.gitignore +18 -0
  4. data/.rspec +2 -0
  5. data/.rubocop.yml +6 -0
  6. data/.travis.yml +12 -0
  7. data/Gemfile +6 -0
  8. data/LICENSE.txt +22 -0
  9. data/README.md +32 -0
  10. data/Rakefile +17 -0
  11. data/lib/planning_center.rb +14 -0
  12. data/lib/planning_center/base.rb +24 -0
  13. data/lib/planning_center/client.rb +63 -0
  14. data/lib/planning_center/errors.rb +5 -0
  15. data/lib/planning_center/lazy_attributes.rb +37 -0
  16. data/lib/planning_center/organization.rb +16 -0
  17. data/lib/planning_center/plan.rb +44 -0
  18. data/lib/planning_center/service_type.rb +9 -0
  19. data/lib/planning_center/version.rb +5 -0
  20. data/planning_center.gemspec +34 -0
  21. data/spec/cassettes/PlanningCenter_Organization/organization.yml +67 -0
  22. data/spec/cassettes/PlanningCenter_Plan/_find/returns_a_plan.yml +133 -0
  23. data/spec/cassettes/PlanningCenter_Plan/_find_all_for_service_type/returns_an_array_of_Plans.yml +69 -0
  24. data/spec/cassettes/PlanningCenter_Plan/_total_length/behaves_like_lazy_attribute/_lazy_method/the_object_is_fully_loaded/returns_the_subject_lazy_value.yml +133 -0
  25. data/spec/cassettes/PlanningCenter_Plan/_total_length/behaves_like_lazy_attribute/_lazy_method/the_object_is_not_fully_loaded/loads_the_full_and_returns_the_lazy_value.yml +199 -0
  26. data/spec/cassettes/PlanningCenter_ServiceType/_plans/returns_an_array_of_plans.yml +69 -0
  27. data/spec/planning_center/base_spec.rb +45 -0
  28. data/spec/planning_center/client_spec.rb +31 -0
  29. data/spec/planning_center/lazy_attributes_spec.rb +50 -0
  30. data/spec/planning_center/organization_spec.rb +19 -0
  31. data/spec/planning_center/plan_spec.rb +33 -0
  32. data/spec/planning_center/service_type_spec.rb +12 -0
  33. data/spec/planning_center_spec.rb +9 -0
  34. data/spec/spec_helper.rb +51 -0
  35. data/spec/support/env.rb +34 -0
  36. data/spec/support/shared_lazy_attribute_examples.rb +27 -0
  37. metadata +249 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a34fc0ff6cc6efb35514fa47bc80165c0b766ac6
4
+ data.tar.gz: b92486be59a5ae785fec458ddade72ca1ed4d342
5
+ SHA512:
6
+ metadata.gz: 88618ede27bed7636e773d461f956053eff6f1a7138849a29fd95b059484af2a426e2ddfdeb6ce8cc47e655d1d64e9b2c9fff427f6928112ef54e2af889aa05a
7
+ data.tar.gz: 845c1693ff0c6a0e4cb4764c557cd158c8d90c06c156880c3456636fba360bc0a716b69f9450b08cbd105978bf549e059745249dab7878e4b429e91f30316b09
data/.env ADDED
@@ -0,0 +1,4 @@
1
+ PCO_TEST_CONSUMER_KEY=xxxxxxxxxxxxxxxxxxxx
2
+ PCO_TEST_CONSUMER_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
3
+ PCO_TEST_ACCESS_TOKEN=xxxxxxxxxxxxxxxxxxxx
4
+ PCO_TEST_ACCESS_TOKEN_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .local.env
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --order random
@@ -0,0 +1,6 @@
1
+ Documentation:
2
+ Enabled: false
3
+ DotPosition:
4
+ EnforcedStyle: trailing
5
+ NumericLiterals:
6
+ Enabled: false
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ rvm:
3
+ - jruby
4
+ - rbx
5
+ - 1.9.2
6
+ - 1.9.3
7
+ - 2.0.0
8
+ - 2.1.0
9
+ addons:
10
+ code_climate:
11
+ repo_token:
12
+ secure: YdXfRrBjmzU1fxEybT8ZbHgMcHUPHaVvKVN/8/b0RECcQvNi/Tmx4b5yjjCaM8T5MTjhy7FljCLMuepGHt4FCUHfoMO2QDEzO0gqZBWsgYY0cNi+4RPimgxe7KGOtURhHwYUk+zplEGxQe9UyvHigrWax86GYIyp3HmRiBtEL0g=
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in planning_center.gemspec
4
+ gemspec
5
+
6
+ gem 'codeclimate-test-reporter', group: :test, require: nil
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Mo Lawson
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,32 @@
1
+ # PlanningCenter
2
+
3
+ [![Build Status](https://img.shields.io/travis/molawson/planning_center.svg)](https://travis-ci.org/molawson/planning_center)
4
+ [![Code Climate](https://img.shields.io/codeclimate/github/molawson/planning_center.svg)](https://codeclimate.com/github/molawson/planning_center)
5
+
6
+ Ruby wrapper for the Planning Center Online API.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'planning_center'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install planning_center
21
+
22
+ ## Usage
23
+
24
+ TODO: Write usage instructions here
25
+
26
+ ## Contributing
27
+
28
+ 1. Fork it ( http://github.com/molawson/planning_center/fork )
29
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
30
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
31
+ 4. Push to the branch (`git push origin my-new-feature`)
32
+ 5. Create new Pull Request
@@ -0,0 +1,17 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ Rubocop::RakeTask.new
7
+
8
+ task default: [:spec, :rubocop]
9
+
10
+ task :console do
11
+ require 'pry'
12
+ require 'planning_center'
13
+ require './spec/support/env'
14
+
15
+ ARGV.clear
16
+ Pry.start
17
+ end
@@ -0,0 +1,14 @@
1
+ # encoding: utf-8
2
+
3
+ require 'planning_center/version'
4
+
5
+ module PlanningCenter
6
+ require 'planning_center/errors'
7
+ require 'planning_center/client'
8
+ require 'planning_center/lazy_attributes'
9
+
10
+ require 'planning_center/base'
11
+ require 'planning_center/organization'
12
+ require 'planning_center/service_type'
13
+ require 'planning_center/plan'
14
+ end
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+
3
+ module PlanningCenter
4
+ class Base
5
+ attr_accessor :attrs
6
+
7
+ def initialize(attrs, client)
8
+ @attrs = attrs
9
+ @client = client
10
+ end
11
+
12
+ def method_missing(method_name, *args)
13
+ attrs.fetch(method_name.to_s) { super }
14
+ end
15
+
16
+ def respond_to_missing?(method_name, include_private = false)
17
+ attrs.key? method_name.to_s
18
+ end
19
+
20
+ private
21
+
22
+ attr_reader :client
23
+ end
24
+ end
@@ -0,0 +1,63 @@
1
+ # encoding: utf-8
2
+
3
+ require 'oauth'
4
+ require 'json'
5
+
6
+ module PlanningCenter
7
+ class Client
8
+ SITE = 'https://planningcenteronline.com'
9
+
10
+ attr_accessor(
11
+ :access_token,
12
+ :access_token_secret,
13
+ :consumer_key,
14
+ :consumer_secret
15
+ )
16
+
17
+ def initialize
18
+ yield(self) if block_given?
19
+ end
20
+
21
+ def organization
22
+ Organization.find(self)
23
+ end
24
+
25
+ def get(path, headers = {})
26
+ response = request(:get, path, headers)
27
+ parse_response(response)
28
+ end
29
+
30
+ private
31
+
32
+ def oauth
33
+ @oauth ||= OAuth::AccessToken.new(
34
+ consumer,
35
+ access_token,
36
+ access_token_secret
37
+ )
38
+ end
39
+
40
+ def consumer
41
+ @consumer ||= OAuth::Consumer.new(
42
+ consumer_key,
43
+ consumer_secret,
44
+ site: SITE
45
+ )
46
+ end
47
+
48
+ def request(type, path, headers)
49
+ oauth.send(type.to_sym, path, headers)
50
+ end
51
+
52
+ def parse_response(response)
53
+ JSON.parse(response.body)
54
+ rescue JSON::ParserError
55
+ raise(
56
+ APIError,
57
+ 'Invalid response from API. ' \
58
+ "Code: #{response.code}, " \
59
+ "Body: #{response.body.inspect} "
60
+ )
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,5 @@
1
+ # encoding: utf-8
2
+
3
+ module PlanningCenter
4
+ class APIError < StandardError; end
5
+ end
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+
3
+ module PlanningCenter
4
+ module LazyAttributes
5
+ module ClassMethods
6
+ private
7
+
8
+ def lazy_accessor(*names)
9
+ names.each do |name|
10
+ define_method(name) do
11
+ load_attrs
12
+ attrs[name.to_s]
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ def self.included(base)
19
+ base.extend(ClassMethods)
20
+ end
21
+
22
+ attr_writer :load_state
23
+
24
+ def load_state
25
+ @load_state ||= :ghost
26
+ end
27
+
28
+ private
29
+
30
+ def load_attrs
31
+ return if load_state == :loaded
32
+
33
+ self.attrs = complete_attrs
34
+ self.load_state = :loaded
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+
3
+ module PlanningCenter
4
+ class Organization < Base
5
+ def self.find(client)
6
+ attrs = client.get('/organization.json')
7
+ new(attrs, client)
8
+ end
9
+
10
+ def service_types
11
+ attrs['service_types'].map do |service_type_attrs|
12
+ ServiceType.new(service_type_attrs, client)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+
3
+ module PlanningCenter
4
+ class Plan < Base
5
+ include LazyAttributes
6
+
7
+ lazy_accessor(
8
+ :service_type,
9
+ :total_length,
10
+ :total_length_formatted,
11
+ :comma_separated_attachment_type_ids,
12
+ :plan_notes,
13
+ :positions,
14
+ :items,
15
+ :service_times,
16
+ :rehearsal_times,
17
+ :other_times,
18
+ :multi_day,
19
+ :attachments,
20
+ :sort_by,
21
+ :plan_people,
22
+ :prev_plan_id,
23
+ :plan_contributions
24
+ )
25
+
26
+ def self.find_all_for_service_type(service_type_id, client)
27
+ plans = client.get("/service_types/#{service_type_id}/plans.json")
28
+ plans.map { |plan| new(plan, client) }
29
+ end
30
+
31
+ def self.find(id, client)
32
+ attrs = client.get("/plans/#{id}.json")
33
+ plan = new(attrs, client)
34
+ plan.load_state = :loaded
35
+ plan
36
+ end
37
+
38
+ private
39
+
40
+ def complete_attrs
41
+ @complete_attrs ||= client.get("/plans/#{id}.json")
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ module PlanningCenter
4
+ class ServiceType < Base
5
+ def plans
6
+ @plans ||= Plan.find_all_for_service_type(id, client)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ # encoding: utf-8
2
+
3
+ module PlanningCenter
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'planning_center/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'planning_center'
8
+ spec.version = PlanningCenter::VERSION
9
+ spec.authors = ['Mo Lawson']
10
+ spec.email = ['mo@molawson.com']
11
+ spec.summary = %q{Ruby wrapper for the Planning Center Online API.}
12
+ spec.description = %q{Ruby wrapper for the Planning Center Online API.}
13
+ spec.homepage = 'https://github.com/molawson/planning_center'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'oauth', '~> 0.4'
22
+ spec.add_dependency 'json', '~> 1.8'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.5'
25
+ spec.add_development_dependency 'rake', '~> 10.1'
26
+ spec.add_development_dependency 'rspec', '~> 2.14'
27
+ spec.add_development_dependency 'vcr', '~> 2.9'
28
+ spec.add_development_dependency 'webmock', '~> 1.17'
29
+ spec.add_development_dependency 'rubocop', '~> 0.20'
30
+
31
+ spec.add_development_dependency 'pry', '~> 0.9'
32
+ spec.add_development_dependency 'dotenv', '~> 0.10'
33
+ spec.add_development_dependency 'awesome_print', '~> 1.2'
34
+ end
@@ -0,0 +1,67 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://planningcenteronline.com/organization.json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - OAuth gem v0.4.7
16
+ Authorization:
17
+ - OAuth oauth_consumer_key="<PCO_CONSUMER_KEY>", oauth_nonce="XCTDkkP3pUhKdUqkZ8cgrLjyxjPVaYTxR6QIH2CEU",
18
+ oauth_signature="GTcNqc8%2BsakqSJzJfiDe4aDEUL0%3D", oauth_signature_method="HMAC-SHA1",
19
+ oauth_timestamp="1397642741", oauth_token="<PCO_ACCESS_TOKEN>", oauth_version="1.0"
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Server:
26
+ - nginx
27
+ Date:
28
+ - Wed, 16 Apr 2014 10:05:45 GMT
29
+ Content-Type:
30
+ - application/json; charset=utf-8
31
+ Content-Length:
32
+ - '517'
33
+ Connection:
34
+ - keep-alive
35
+ Status:
36
+ - 200 OK
37
+ Last-Modified:
38
+ - Wed, 16 Apr 2014 10:05:41 GMT
39
+ Expires:
40
+ - '0'
41
+ Pragma:
42
+ - no-cache
43
+ Cache-Control:
44
+ - must-revalidate, no-cache, no-store, private, max-age=0, post-check=0, pre-check=0
45
+ X-Ua-Compatible:
46
+ - IE=Edge,chrome=1
47
+ Set-Cookie:
48
+ - _account_center_session=BAh7BkkiD3Nlc3Npb25faWQGOgZFVEkiJTE5NzBiMjc1NjcyOWM4YzAyYTM4ZDQxYTcwYTQ2NjgwBjsAVA%3D%3D--36e04f1e4b6c74a172817843dec9bf56ef6d2e50;
49
+ domain=.planningcenteronline.com; path=/; expires=Wed, 30-Apr-2014 10:05:41
50
+ GMT; HttpOnly
51
+ X-Request-Id:
52
+ - 44a8e86e8f5e312837dd85e4c08ca4a8
53
+ X-Runtime:
54
+ - '0.029507'
55
+ X-Rack-Cache:
56
+ - miss
57
+ X-Cache:
58
+ - MISS
59
+ body:
60
+ encoding: UTF-8
61
+ string: "{\"id\":58851,\"account_center_id\":96557,\"name\":\"The Bridgeway
62
+ Church\",\"owner_name\":\"Mo Lawson\",\"music_stand_enabled\":null,\"projector_enabled\":null,\"ccli_connected\":false,\"secret\":1357536549,\"date_format\":2,\"twenty_four_hour_time\":false,\"total_songs\":49,\"total_people\":4,\"service_types\":[{\"id\":230211,\"name\":\"Weekend
63
+ Service\",\"parent_id\":0,\"type\":\"ServiceType\",\"container\":\"The Bridgeway
64
+ Church\",\"container_id\":null,\"sequence\":0,\"attachment_types_enabled\":false,\"permissions\":\"Administrator\"}],\"service_type_folders\":[]}"
65
+ http_version:
66
+ recorded_at: Wed, 16 Apr 2014 10:05:42 GMT
67
+ recorded_with: VCR 2.9.0