-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit, from gem release 1.0.1
- Loading branch information
0 parents
commit 4fd4248
Showing
30 changed files
with
827 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/pkg | ||
.rvmrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
language: ruby | ||
rvm: | ||
- 1.8.7 | ||
- 1.9.2 | ||
- 1.9.3 | ||
- 2.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Iskander Haziev <gvalmon@gmail.com> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
source "https://rubygems.org" | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
civicrm (1.0.1) | ||
activemodel | ||
activesupport | ||
nokogiri | ||
rest-client (~> 1.4) | ||
|
||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
activemodel (3.2.13) | ||
activesupport (= 3.2.13) | ||
builder (~> 3.0.0) | ||
activesupport (3.2.13) | ||
i18n (= 0.6.1) | ||
multi_json (~> 1.0) | ||
builder (3.0.4) | ||
diff-lcs (1.2.1) | ||
i18n (0.6.1) | ||
metaclass (0.0.1) | ||
mime-types (1.22) | ||
mocha (0.10.5) | ||
metaclass (~> 0.0.1) | ||
multi_json (1.7.2) | ||
nokogiri (1.5.9) | ||
rake (10.0.3) | ||
rest-client (1.6.7) | ||
mime-types (>= 1.16) | ||
rspec (2.13.0) | ||
rspec-core (~> 2.13.0) | ||
rspec-expectations (~> 2.13.0) | ||
rspec-mocks (~> 2.13.0) | ||
rspec-core (2.13.1) | ||
rspec-expectations (2.13.0) | ||
diff-lcs (>= 1.1.3, < 2.0) | ||
rspec-mocks (2.13.0) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
civicrm! | ||
mocha | ||
rake | ||
rspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
=== 1.0 2013-04-8 | ||
|
||
* 1 major enhancement: | ||
* Initial release | ||
|
||
=== 1.1 2013-05-8 | ||
|
||
* 3 minor enhancements: | ||
* Fix gem specs | ||
* added CiviCrm::XML.encode method | ||
* CiviCrm::Client.request not accepts only 2 params, "path" option is removed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License | ||
|
||
Copyright (c) 2013 CiviCrm.com. (https://civicrm.com) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
## Installation | ||
|
||
* $ gem install civicrm | ||
|
||
## Getting started | ||
|
||
```ruby | ||
* CiviCrm.site_key = 'YOUR_SITE_KEY' | ||
* // More info about site_key: | ||
* // http://wiki.civicrm.org/confluence/display/CRMDOC43/Managing+Scheduled+Jobs | ||
* CiviCrm.api_base = 'https://www.example.org/path/to/civi/codebase/' | ||
* CiviCrm.authenticate('demo', 'demo') | ||
``` | ||
|
||
## CiviCrm Objects | ||
|
||
```ruby | ||
* CiviCrm::Contact.all # get list of contacts | ||
* CiviCrm::Contact.create(contact_type: 'Organization', organization_name: 'test') # create contact | ||
* CiviCrm::Contact.find(1).delete # find and delete | ||
``` | ||
|
||
## Testing | ||
``` | ||
rspec spec | ||
``` | ||
|
||
## Useful links | ||
|
||
* http://wiki.civicrm.org/confluence/display/CRMDOC43/REST+interface | ||
* http://drupal.demo.civicrm.org/civicrm/api/explorer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require 'bundler' | ||
Bundler::GemHelper.install_tasks | ||
|
||
require 'rake' | ||
require 'rspec/core/rake_task' | ||
|
||
desc "Run all examples" | ||
RSpec::Core::RakeTask.new(:spec) do |t| | ||
t.rspec_opts = %w[--color] | ||
end | ||
|
||
task :default => [:spec] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env ruby | ||
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb' | ||
|
||
libs = " -r irb/completion" | ||
libs << " -r #{File.dirname(__FILE__) + '/../lib/civicrm'}" | ||
puts "Loading CiviCrm gem" | ||
exec "#{irb} #{libs} --simple-prompt" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
$:.unshift(File.join(File.dirname(__FILE__), 'lib')) | ||
|
||
require 'civicrm/version' | ||
|
||
spec = Gem::Specification.new do |s| | ||
s.name = 'civicrm' | ||
s.version = CiviCrm::VERSION | ||
s.summary = 'Ruby bindings for the CiviCRM API' | ||
s.description = 'See http://civicrm.org for details.' | ||
s.authors = ['Iskander Haziev'] | ||
s.email = ['gvalmon@gmail.com'] | ||
s.homepage = 'http://civicrm.org' | ||
s.executables = 'civicrm' | ||
s.require_paths = %w{lib} | ||
|
||
s.add_dependency('rest-client', '~> 1.4') | ||
s.add_dependency('activesupport') | ||
s.add_dependency('activemodel') | ||
s.add_dependency('nokogiri') | ||
|
||
s.add_development_dependency('rake') | ||
s.add_development_dependency('rspec') | ||
s.add_development_dependency('mocha') | ||
|
||
s.files = `git ls-files`.split("\n") | ||
s.test_files = `git ls-files -- test/*`.split("\n") | ||
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } | ||
s.require_paths = ['lib'] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
require 'active_support/deprecation' | ||
require 'active_support/core_ext/module' | ||
require 'active_support/core_ext/hash' | ||
require 'active_support/inflector' | ||
require 'rest-client' | ||
require 'nokogiri' | ||
|
||
# utils | ||
require 'civicrm/client' | ||
require 'civicrm/xml' | ||
require 'civicrm/resource' | ||
require 'civicrm/version' | ||
|
||
# actions | ||
require 'civicrm/actions/list' | ||
require 'civicrm/actions/create' | ||
require 'civicrm/actions/update' | ||
require 'civicrm/actions/destroy' | ||
require 'civicrm/actions/find' | ||
|
||
# exceptions | ||
require 'civicrm/errors' | ||
|
||
# resources | ||
require 'civicrm/resources/base' | ||
|
||
module CiviCrm | ||
@@api_key = nil | ||
@@site_key = nil | ||
@@api_base = 'https://www.example.org/path/to/civi/codebase' | ||
@@api_version = 'v3' | ||
@@user_authenticated = false | ||
|
||
mattr_accessor :api_key, :api_base, :api_version, :site_key | ||
|
||
def self.api_url(path = '') | ||
base = "#{api_base}/civicrm/extern/rest.php?#{path}" | ||
base += "&api_key=#{@@api_key}" if @@api_key | ||
base += "&key=#{@@site_key}" if @@site_key | ||
base | ||
end | ||
|
||
def self.authenticate(name, password) | ||
auth = Client.request(:post, q: 'civicrm/login', name: name, pass: password) | ||
@@api_key = auth[0]['api_key'] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module CiviCrm | ||
module Actions | ||
module Create | ||
module ClassMethods | ||
def create(attrs = {}) | ||
params = {'entity' => entity_class_name, 'action' => 'create'} | ||
response = CiviCrm::Client.request(:post, params.merge(attrs)) | ||
Resource.build_from(response.first, params) | ||
end | ||
end | ||
|
||
def self.included(base) | ||
base.extend(ClassMethods) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module CiviCrm | ||
module Actions | ||
module Destroy | ||
def delete | ||
params = {'entity' => self.class.entity_class_name, 'action' => 'delete', 'id' => id} | ||
response = CiviCrm::Client.request(:post, params) | ||
refresh_from(response.first.to_hash) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module CiviCrm | ||
module Actions | ||
module Find | ||
module ClassMethods | ||
def find(id) | ||
params = {'entity' => entity_class_name, 'action' => 'getsingle', 'id' => id} | ||
response = CiviCrm::Client.request(:get, params) | ||
Resource.build_from(response.first, params) | ||
end | ||
end | ||
|
||
def self.included(base) | ||
base.extend(ClassMethods) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module CiviCrm | ||
module Actions | ||
module List | ||
module ClassMethods | ||
def all(params = {}) | ||
params.merge!('entity' => entity_class_name, 'action' => 'get') | ||
response = CiviCrm::Client.request(:get, params) | ||
Resource.build_from(response, params) | ||
end | ||
|
||
def count | ||
all.count | ||
end | ||
|
||
def first | ||
all.first | ||
end | ||
|
||
def last | ||
all.last | ||
end | ||
end | ||
|
||
def self.included(base) | ||
base.extend(ClassMethods) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module CiviCrm | ||
module Actions | ||
module Update | ||
# TODO: this method doesn't work yet | ||
def update(attrs = {}) | ||
params = {'entity' => self.class.entity_class_name, 'action' => 'replace', 'id' => id} | ||
new_attrs = attributes.merge(attrs) | ||
response = CiviCrm::Client.request(:post, params.merge(values: new_attrs)) | ||
refresh_from(response.first.to_hash) | ||
end | ||
|
||
def save | ||
@previously_changed = changes | ||
@changed_attributes.clear | ||
update() | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.