Skip to content

Commit

Permalink
Initial commit, from gem release 1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
wioux committed May 11, 2018
0 parents commit 4fd4248
Show file tree
Hide file tree
Showing 30 changed files with 827 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/pkg
.rvmrc
6 changes: 6 additions & 0 deletions .travis.yml
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
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Iskander Haziev <gvalmon@gmail.com>
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
source "https://rubygems.org"
gemspec
47 changes: 47 additions & 0 deletions Gemfile.lock
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
11 changes: 11 additions & 0 deletions History.txt
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
21 changes: 21 additions & 0 deletions LICENSE
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.
31 changes: 31 additions & 0 deletions README.md
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
12 changes: 12 additions & 0 deletions Rakefile
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]
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.0
7 changes: 7 additions & 0 deletions bin/civicrm
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"
29 changes: 29 additions & 0 deletions civicrm.gemspec
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
47 changes: 47 additions & 0 deletions lib/civicrm.rb
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
17 changes: 17 additions & 0 deletions lib/civicrm/actions/create.rb
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
11 changes: 11 additions & 0 deletions lib/civicrm/actions/destroy.rb
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
17 changes: 17 additions & 0 deletions lib/civicrm/actions/find.rb
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
29 changes: 29 additions & 0 deletions lib/civicrm/actions/list.rb
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
19 changes: 19 additions & 0 deletions lib/civicrm/actions/update.rb
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
Loading

0 comments on commit 4fd4248

Please sign in to comment.