blackbaud-client 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OWI4MTAwMjg4NGU0Yjk2NjZlNGYzNDJjYWJiNjFjYTc1NDg3ZjVjZg==
4
+ ZDYxY2VhMGY4M2MzNWI4NGQ1NGYxYTg2YzVlNDg2ZjhiNzUwZWVhMQ==
5
5
  data.tar.gz: !binary |-
6
- OTI2ZTQwNzg4MTY0YTIzYjk5ODA2MjMwYjFlOWI4NGU2MzNhNzU4MA==
6
+ MThhYWYxNTJjNmMzZmZjYjNlOTk4ZGM3YThlNjI1MjI5ZTM3MTFmNQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MzU2YWIzZGE1YTA3NjhjMTAwNjM2YWNlZDA3MzY5M2QzOTRiMjQxN2EyMjE0
10
- NjY3NTZiYTEyZjZjNzNmZGQyNmU3MmU4MzJlZTY3MTk5NjYyYjI4ZjU4ZjNl
11
- ZWEwMTRjYjg5Njg2N2JkNDlkYzQ3NzkwMzgxZThlOTBlNzExNWM=
9
+ NjdmZGIwNTM1MTA1MzY0NjBhNTVkZDRiYWVhODNhMjM3ZWE1NzdjM2Y4OTlh
10
+ Y2Q5ZGYyMjA4NzNiZjI4YmQ0YWUyZjJmNmRlM2VkM2Y3YTgzYWNhNTVlNDBm
11
+ MTlkYzUyMjUxY2NmOWQ5ZDM2MTY4Y2I2YjQxZTdmYjFjN2QyNjM=
12
12
  data.tar.gz: !binary |-
13
- NTdjNGMxZWVlYzAwZDg0NTNkZmZjYWQ1ZTcyODcxN2E0NGU2ZmU1YzIzNDQw
14
- OTNjOWEwYTdiZWM0MmQ0NWQ2ZTYyMGRiOGUzODIzMGZkNmU3MzIzYjM4NWJl
15
- ZDVjYTBkZmYwNTZmNTg5ZmQ0Y2MyYjRjNWU4YzY0YzRhMDIwNGQ=
13
+ NWZlMWZjNWFjZWYxNjVkZjRhY2JlYTBkOGZmY2M4ZTBjMTM1NTJmNDA5ZGUz
14
+ MjhiMjQ0OWRmYTI2NDVlMmQ2NmFlNGU0YTQ4NGYzZmUzOGIwNmFhODRhNTY5
15
+ Njc4ZjdiM2I3NzY4MzVlYTBjYzUyMGQxN2M3YWM2NGNlNWIzYjA=
data/.gitignore CHANGED
@@ -3,4 +3,5 @@
3
3
  example.rb
4
4
  test/
5
5
  .ruby-version
6
- .ruby-gemset
6
+ .ruby-gemset
7
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+
@@ -2,9 +2,11 @@
2
2
  lib = File.expand_path('../lib/', __FILE__)
3
3
  $:.unshift lib unless $:.include?(lib)
4
4
 
5
+ require 'blackbaud-client/version'
6
+
5
7
  Gem::Specification.new do |gem|
6
8
  gem.name = "blackbaud-client"
7
- gem.version = "0.0.5"
9
+ gem.version = Blackbaud::Client::Version.to_s
8
10
  gem.authors = "Alex Dugger"
9
11
  gem.email = "alexd@haikulearning.com"
10
12
  gem.description = "A client for the Blackbaud API."
@@ -12,7 +14,7 @@ Gem::Specification.new do |gem|
12
14
  gem.summary = "A client for the Blackbaud API."
13
15
  gem.files = `git ls-files`.split($/)
14
16
  gem.require_path = 'lib'
15
- gem.add_runtime_dependency 'ruby-hmac'
16
- gem.add_runtime_dependency 'rest-client'
17
17
 
18
+ gem.add_runtime_dependency 'ruby-hmac', '~>0.4'
19
+ gem.add_runtime_dependency 'rest-client', '~>1.6'
18
20
  end
@@ -3,7 +3,6 @@ module Blackbaud
3
3
  attr_accessor(:description, :ea7_academic_year_id, :end_date, :school_id, :school_name, :sessions, :short_description, :start_date, :links)
4
4
 
5
5
  def initialize(values)
6
-
7
6
  values["sessions"].map! {|s| Blackbaud::Session.new(s)} if values["sessions"]
8
7
 
9
8
  ["start_date", "end_date"].each do |date|
@@ -11,9 +10,7 @@ module Blackbaud
11
10
  values.delete("#{date}")
12
11
  end
13
12
 
14
- values.each do |k,v|
15
- send("#{k}=".intern, v)
16
- end
13
+ super(values)
17
14
 
18
15
  def connection_string
19
16
  "academic_years/#{self.ea7_academic_year_id}"
@@ -22,7 +19,6 @@ module Blackbaud
22
19
  def terms
23
20
  self.sessions.inject([]) {|r, s| r + s.terms}
24
21
  end
25
-
26
22
  end
27
23
 
28
24
  end
@@ -1,6 +1,14 @@
1
1
  module Blackbaud
2
2
  class BlackbaudObject
3
3
 
4
+ def initialize(values)
5
+ values.each do |k,v|
6
+ if respond_to?("#{k}=".intern)
7
+ send("#{k}=".intern, v)
8
+ end
9
+ end
10
+ end
11
+
4
12
  def format_date(d)
5
13
  DateTime.parse(d)
6
14
  end
@@ -3,13 +3,9 @@ module Blackbaud
3
3
  attr_accessor(:ea7_class_id, :course_id, :course_name, :section, :ea7_term_id, :ea7_term_name, :faculty, :students)
4
4
 
5
5
  def initialize(values)
6
-
7
6
  values["faculty"].map! {|s| Blackbaud::Person.new(s, 1)} if values["faculty"]
8
7
  values["students"].map! {|s| Blackbaud::Person.new(s, 2)} if values["students"]
9
-
10
- values.each do |k,v|
11
- send("#{k}=".intern, v)
12
- end
8
+ super(values)
13
9
  end
14
10
 
15
11
  end
@@ -1,13 +1,5 @@
1
1
  module Blackbaud
2
2
  class CodeTable < BlackbaudObject
3
3
  attr_accessor(:_links, :id, :name, :links)
4
-
5
- def initialize(values)
6
-
7
- values.each do |k,v|
8
- send("#{k}=".intern, v)
9
- end
10
- end
11
-
12
4
  end
13
5
  end
@@ -0,0 +1,5 @@
1
+ module Blackbaud
2
+ class CodeTableEntry < BlackbaudObject
3
+ attr_accessor(:id, :name)
4
+ end
5
+ end
@@ -1,12 +1,5 @@
1
1
  module Blackbaud
2
2
  class Contact < BlackbaudObject
3
3
  attr_accessor(:type_id, :type_value, :value)
4
-
5
- def initialize(values)
6
- values.each do |k,v|
7
- send("#{k}=".intern, v)
8
- end
9
- end
10
-
11
4
  end
12
5
  end
@@ -1,9 +1,14 @@
1
1
  module Blackbaud
2
2
  class Person < BlackbaudObject
3
- attr_accessor(:ea7_record_id, :name_for_display, :type, :birth_date, :first_name, :import_id, :last_name, :record_type, :title, :suffix, :middle_name, :user_defined_id, :nickname, :contacts)
3
+ attr_accessor(:ea7_record_id, :name_for_display, :type, :birth_date, :first_name, :import_id, :last_name, :record_type, :title, :suffix, :middle_name, :user_defined_id, :nickname, :contacts, :relations, :online_user_id)
4
4
 
5
- def initialize(values, type_id)
5
+ USER_TYPE = {
6
+ :faculty => 1,
7
+ :student => 2,
8
+ :undefined => nil,
9
+ }
6
10
 
11
+ def initialize(values, type_id)
7
12
  values["type"] = type_id
8
13
 
9
14
  if values["bio"]
@@ -12,15 +17,33 @@ module Blackbaud
12
17
  end
13
18
 
14
19
  if values["contact_info"]
15
- values["contacts"] = values["contact_info"].map! {|c| Blackbaud::Contact.new(c)}
20
+ values["contacts"] = values["contact_info"].map {|c| Blackbaud::Contact.new(c)}
16
21
  values.delete("contact_info")
22
+ else
23
+ values["contacts"] = []
24
+ end
25
+
26
+ if values["relations"]
27
+ values["relations"].map! {|r| Blackbaud::Relation.new(r)}
28
+ else
29
+ values["relations"] = []
17
30
  end
18
31
 
19
32
  values["birth_date"] = format_date(values["birth_date"]) if values["birth_date"]
20
33
 
21
- values.each do |k,v|
22
- send("#{k}=".intern, v)
23
- end
34
+ super(values)
35
+ end
36
+
37
+ def faculty?
38
+ type == USER_TYPE[:faculty]
39
+ end
40
+
41
+ def student?
42
+ type == USER_TYPE[:student]
43
+ end
44
+
45
+ def undefined_type?
46
+ type == USER_TYPE[:undefined]
24
47
  end
25
48
 
26
49
  end
@@ -0,0 +1,16 @@
1
+ module Blackbaud
2
+ class Relation < BlackbaudObject
3
+ attr_accessor(:relationship_code_id, :relationship_code_value, :reciprocal_code_id, :reciprocal_code_value, :person)
4
+
5
+ def initialize(values)
6
+ if values["person"]
7
+ values["person"] = Blackbaud::Person.new(values["person"], Blackbaud::Person::USER_TYPE[:undefined])
8
+ end
9
+
10
+ values.each do |k,v|
11
+ send("#{k}=".intern, v)
12
+ end
13
+ end
14
+
15
+ end
16
+ end
@@ -3,13 +3,8 @@ module Blackbaud
3
3
  attr_accessor(:name, :ea7_session_id, :terms, :links)
4
4
 
5
5
  def initialize(values)
6
-
7
6
  values["terms"].map! {|t| Blackbaud::Term.new(t)} if values["terms"]
8
-
9
- values.each do |k,v|
10
- send("#{k}=".intern, v)
11
- end
12
-
7
+ super(values)
13
8
  end
14
9
 
15
10
  end
@@ -1,13 +1,5 @@
1
1
  module Blackbaud
2
2
  class StaticCodeTable < BlackbaudObject
3
3
  attr_accessor(:id, :name, :links)
4
-
5
- def initialize(values)
6
-
7
- values.each do |k,v|
8
- send("#{k}=".intern, v)
9
- end
10
- end
11
-
12
4
  end
13
5
  end
@@ -1,13 +1,5 @@
1
1
  module Blackbaud
2
2
  class TableEntry < BlackbaudObject
3
3
  attr_accessor(:id, :name)
4
-
5
- def initialize(values)
6
-
7
- values.each do |k,v|
8
- send("#{k}=".intern, v)
9
- end
10
- end
11
-
12
4
  end
13
5
  end
@@ -2,14 +2,6 @@ module Blackbaud
2
2
  class Term < BlackbaudObject
3
3
  attr_accessor(:ea7_term_id, :name, :links)
4
4
 
5
- def initialize(values)
6
-
7
- values.each do |k,v|
8
- send("#{k}=".intern, v)
9
- end
10
-
11
- end
12
-
13
5
  def connection_string
14
6
  "terms/#{self.ea7_term_id}"
15
7
  end
@@ -0,0 +1,20 @@
1
+ module Blackbaud
2
+ class Client
3
+ class Version
4
+ MAJOR = 0
5
+ MINOR = 1
6
+ PATCH = 0
7
+ STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
8
+
9
+ class << self
10
+ # A String representing the current version of the OEmbed gem.
11
+ def inspect
12
+ STRING
13
+ end
14
+ alias_method :to_s, :inspect
15
+ end
16
+ end
17
+
18
+ VERSION = Version::STRING
19
+ end
20
+ end
@@ -1,14 +1,16 @@
1
+ require 'blackbaud-client/version.rb'
1
2
  require 'blackbaud-client/api/blackbaud_object.rb'
2
3
  require 'blackbaud-client/api/academic_year.rb'
3
4
  require 'blackbaud-client/api/class.rb'
4
5
  require 'blackbaud-client/api/code_table.rb'
5
6
  require 'blackbaud-client/api/person.rb'
7
+ require 'blackbaud-client/api/contact.rb'
8
+ require 'blackbaud-client/api/relation.rb'
6
9
  require 'blackbaud-client/api/session.rb'
7
10
  require 'blackbaud-client/api/static_code_table.rb'
8
11
  require 'blackbaud-client/api/table_entry.rb'
9
12
  require 'blackbaud-client/api/term.rb'
10
- require 'blackbaud-client/api/contact_type.rb'
11
- require 'blackbaud-client/api/contact.rb'
13
+ require 'blackbaud-client/api/code_table_entry.rb'
12
14
  require 'hmac-sha1'
13
15
  require 'cgi'
14
16
  require 'base64'
@@ -19,11 +21,6 @@ require 'date'
19
21
  module Blackbaud
20
22
  class Client
21
23
 
22
- USER_TYPE = {
23
- :faculty => 1,
24
- :student => 2
25
- }
26
-
27
24
  def initialize(options)
28
25
  auth_params = {
29
26
  :database_key => options[:database_key],
@@ -36,14 +33,10 @@ module Blackbaud
36
33
 
37
34
  end
38
35
 
39
- def construct_url(web_services_url, endpoint, filters=nil)
40
- @url = "#{web_services_url}/#{endpoint}?token=#{@token}"
41
- @url << "&filter=(#{filters})" if filters
42
- end
43
-
44
36
  def connect(endpoint, filters=nil)
45
- construct_url(@web_services_url, endpoint, filters)
46
- JSON.parse(RestClient::Request.execute(:method=>'get', :url=>@url))
37
+ url = construct_url(@web_services_url, endpoint, filters)
38
+ #puts url.inspect
39
+ JSON.parse(RestClient::Request.execute(:method=>'get', :url=>url))
47
40
  end
48
41
 
49
42
  def academic_years(id)
@@ -53,17 +46,40 @@ module Blackbaud
53
46
 
54
47
  def contact_types
55
48
  results = connect("global/code_tables/phone%20type")
56
- results["table_entries"].collect {|ct| Blackbaud::ContactType.new(ct)}
49
+ results["table_entries"].collect {|entry| Blackbaud::CodeTableEntry.new(entry)}
50
+ end
51
+
52
+ def relationships
53
+ results = connect("global/code_tables/relationship")
54
+ results["table_entries"].collect {|entry| Blackbaud::CodeTableEntry.new(entry)}
57
55
  end
58
56
 
59
- def people(scope, contact_types=nil)
60
- filter = contact_types.is_a?(Array) ? "contact.type_id%20eq%20#{contact_types.join(',')}" : nil
61
- results = connect("person/#{scope.connection_string}/people", filter )
62
- r = [:faculty, :students].collect do |t|
63
- p = results["people"].first[t.to_s]
64
- (p.nil? ? [] : p.collect {|person| Blackbaud::Person.new(person, (USER_TYPE[t]))})
57
+ # Return an Array of Person records
58
+ #
59
+ # Available filter_opts:
60
+ # * :contact_types: An Array of id values that correspond to code_table table_entry records from the "phone type" code_table
61
+ # * :relationships: An Array of id values that correspond to code_table table_entry records from the "relationship" code_table
62
+ def people(scope, filter_opts={})
63
+ filters = {}
64
+
65
+ filters["contact.type_id"] = filter_opts[:contact_types]
66
+ filters["relation.relationship_code_id"] = filter_opts[:relationships]
67
+
68
+ results = connect("person/#{scope.connection_string}/people", filters )
69
+ r = []
70
+
71
+ {
72
+ 'faculty' => Blackbaud::Person::USER_TYPE[:faculty],
73
+ 'students' => Blackbaud::Person::USER_TYPE[:student],
74
+ }.each do |response_key, type_id|
75
+ ppl = results["people"].first[response_key]
76
+ ppl = [] unless ppl.is_a?(Enumerable)
77
+ ppl.each do |person|
78
+ r << Blackbaud::Person.new(person, type_id)
79
+ end
65
80
  end
66
- r.flatten(1)
81
+
82
+ r
67
83
  end
68
84
 
69
85
  def classes(scope)
@@ -85,5 +101,20 @@ module Blackbaud
85
101
  results = connect("global/static_code_tables/#{id}")
86
102
  results["table_entries"].collect {|c| Blackbaud::TableEntry.new(c)}
87
103
  end
104
+
105
+ private
106
+
107
+ def construct_url(web_services_url, endpoint, filters=nil)
108
+ url = "#{web_services_url}/#{endpoint}?token=#{@token}"
109
+ filters = Array(filters).map do |k,v|
110
+ v = Array(v)
111
+ "(#{k}%20eq%20#{v.join(',')})" if v && !v.join.empty?
112
+ end
113
+
114
+ url << "&filter=#{filters.join}"
115
+
116
+ url
117
+ end
118
+
88
119
  end
89
120
  end
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blackbaud-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Dugger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-15 00:00:00.000000000 Z
11
+ date: 2014-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-hmac
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '0.4'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '0.4'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rest-client
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '1.6'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '1.6'
41
41
  description: A client for the Blackbaud API.
42
42
  email: alexd@haikulearning.com
43
43
  executables: []
@@ -45,6 +45,7 @@ extensions: []
45
45
  extra_rdoc_files: []
46
46
  files:
47
47
  - .gitignore
48
+ - Gemfile
48
49
  - LICENSE.txt
49
50
  - README.md
50
51
  - blackbaud-client.gemspec
@@ -53,13 +54,15 @@ files:
53
54
  - lib/blackbaud-client/api/blackbaud_object.rb
54
55
  - lib/blackbaud-client/api/class.rb
55
56
  - lib/blackbaud-client/api/code_table.rb
57
+ - lib/blackbaud-client/api/code_table_entry.rb
56
58
  - lib/blackbaud-client/api/contact.rb
57
- - lib/blackbaud-client/api/contact_type.rb
58
59
  - lib/blackbaud-client/api/person.rb
60
+ - lib/blackbaud-client/api/relation.rb
59
61
  - lib/blackbaud-client/api/session.rb
60
62
  - lib/blackbaud-client/api/static_code_table.rb
61
63
  - lib/blackbaud-client/api/table_entry.rb
62
64
  - lib/blackbaud-client/api/term.rb
65
+ - lib/blackbaud-client/version.rb
63
66
  homepage: https://github.com/haikulearning/blackbaud-api-client
64
67
  licenses: []
65
68
  metadata: {}
@@ -1,12 +0,0 @@
1
- module Blackbaud
2
- class ContactType < BlackbaudObject
3
- attr_accessor(:id, :name)
4
-
5
- def initialize(values)
6
- values.each do |k,v|
7
- send("#{k}=".intern, v)
8
- end
9
- end
10
-
11
- end
12
- end