databasedotcom-convenience 1.0.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.
- data/MIT-LICENSE +22 -0
- data/README.md +97 -0
- data/lib/databasedotcom-convenience.rb +1 -0
- data/lib/databasedotcom/convenience.rb +3 -0
- data/lib/databasedotcom/convenience/base.rb +62 -0
- data/lib/databasedotcom/convenience/version.rb +5 -0
- metadata +115 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2012 Johnneylee Jack Rollins
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
# databasedotcom-convenience
|
2
|
+
|
3
|
+
A convenience module to make talking to databasedotcom convenient.
|
4
|
+
|
5
|
+
#Installation
|
6
|
+
gem install databasedotcom-convenience
|
7
|
+
|
8
|
+
or, if you use Bundler
|
9
|
+
|
10
|
+
gem 'databasedotcom-convenience'
|
11
|
+
|
12
|
+
# Usage
|
13
|
+
|
14
|
+
* Include `Databasedotcom::Convenience` into your class
|
15
|
+
|
16
|
+
* Create a YAML file at 'config/databasedotcom.yml' derived from your project root.
|
17
|
+
* Example below:
|
18
|
+
|
19
|
+
---
|
20
|
+
client_id: put-your-client-id-here
|
21
|
+
client_secret: put-your-client-secret-here
|
22
|
+
username: put-your-username-here
|
23
|
+
password: put-your-password-here
|
24
|
+
debugging: true
|
25
|
+
|
26
|
+
Alternatively, include environment-specific settings:
|
27
|
+
development:
|
28
|
+
client_id: ...
|
29
|
+
test:
|
30
|
+
client_id: ...
|
31
|
+
production:
|
32
|
+
client_id: ...
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
# Rails example
|
37
|
+
|
38
|
+
class UsersController < ApplicationController
|
39
|
+
include Databasedotcom::Convenience
|
40
|
+
before_filter :load_user, :except => [:index, :new]
|
41
|
+
|
42
|
+
def index
|
43
|
+
@users = User.all
|
44
|
+
end
|
45
|
+
|
46
|
+
def show
|
47
|
+
end
|
48
|
+
|
49
|
+
def new
|
50
|
+
@user = User.new
|
51
|
+
end
|
52
|
+
|
53
|
+
def create
|
54
|
+
User.create User.coerce_params(params[:user])
|
55
|
+
flash[:info] = "The user was created!"
|
56
|
+
redirect_to users_path
|
57
|
+
end
|
58
|
+
|
59
|
+
def edit
|
60
|
+
end
|
61
|
+
|
62
|
+
def update
|
63
|
+
@user.update_attributes User.coerce_params(params[:user])
|
64
|
+
flash[:info] = "The user was updated!"
|
65
|
+
redirect_to user_path(@user)
|
66
|
+
end
|
67
|
+
|
68
|
+
def destroy
|
69
|
+
@user.delete
|
70
|
+
flash[:info] = "The user was deleted!"
|
71
|
+
redirect_to users_path
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def load_user
|
77
|
+
@user = User.find(params[:id])
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# Example
|
82
|
+
module Service::Databasedotcom
|
83
|
+
include Databasedotcom::Convenience
|
84
|
+
|
85
|
+
def self.build_user id
|
86
|
+
@user = User.find id
|
87
|
+
@user['fullname'] = [@user.first_name, @user.last_name].join " "
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
This is a contrived example. Check out the `databasedotcom` gem for more information on querying.
|
92
|
+
|
93
|
+
Note that there is no need to declare the User class anywhere- `Databasedotcom::Convenience` recognizes it as a known Sobject type from your database.com instance, and materializes it automatically.
|
94
|
+
|
95
|
+
# License
|
96
|
+
|
97
|
+
databasedotcom-convenience is released under the MIT License
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'databasedotcom/convenience'
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Databasedotcom
|
2
|
+
module Convenience
|
3
|
+
|
4
|
+
def self.env
|
5
|
+
return ENV['RAILS_ENV'].to_sym unless ENV['RAILS_ENV'].nil?
|
6
|
+
return ENV['RACK_ENV'].to_sym unless ENV['RACK_ENV'].nil?
|
7
|
+
return ENV['APP_ENV'].to_sym unless ENV['APP_ENV'].nil?
|
8
|
+
return :development
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
|
13
|
+
def dbdc_client
|
14
|
+
unless @dbdc_client
|
15
|
+
config = YAML.load_file(File.join(File.join Dir.pwd, 'config', 'databasedotcom.yml'))
|
16
|
+
config = config.has_key?(::Databasedotcom::Convenience.env) ? config[::Databasedotcom::Convenience.env] : config
|
17
|
+
username = config["username"]
|
18
|
+
password = config["password"]
|
19
|
+
@dbdc_client = Databasedotcom::Client.new(config)
|
20
|
+
@dbdc_client.authenticate(:username => username, :password => password)
|
21
|
+
end
|
22
|
+
|
23
|
+
@dbdc_client
|
24
|
+
end
|
25
|
+
|
26
|
+
def dbdc_client=(client)
|
27
|
+
@dbdc_client = client
|
28
|
+
end
|
29
|
+
|
30
|
+
def sobject_types
|
31
|
+
unless @sobject_types
|
32
|
+
@sobject_types = dbdc_client.list_sobjects
|
33
|
+
end
|
34
|
+
|
35
|
+
@sobject_types
|
36
|
+
end
|
37
|
+
|
38
|
+
def const_missing(sym)
|
39
|
+
if sobject_types.include?(sym.to_s)
|
40
|
+
dbdc_client.materialize(sym.to_s)
|
41
|
+
else
|
42
|
+
super
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
module InstanceMethods
|
48
|
+
def dbdc_client
|
49
|
+
self.class.dbdc_client
|
50
|
+
end
|
51
|
+
|
52
|
+
def sobject_types
|
53
|
+
self.class.sobject_types
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.included(base)
|
58
|
+
base.send(:include, InstanceMethods)
|
59
|
+
base.send(:extend, ClassMethods)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: databasedotcom-convenience
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Johnneylee Jack Rollins
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-26 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: databasedotcom
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - '='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.6.0
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - '='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.6.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - '='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.8.6
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.8.6
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: pry
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - '='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.9.10
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - '='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 0.9.10
|
78
|
+
description: Convenience classes to make using the databasedotcom gem even easier
|
79
|
+
email:
|
80
|
+
- Johnneylee Jack Rollins
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- README.md
|
86
|
+
- MIT-LICENSE
|
87
|
+
- lib/databasedotcom/convenience/base.rb
|
88
|
+
- lib/databasedotcom/convenience/version.rb
|
89
|
+
- lib/databasedotcom/convenience.rb
|
90
|
+
- lib/databasedotcom-convenience.rb
|
91
|
+
homepage: http://github.com/Spaceghost/databasedotcom-convenience
|
92
|
+
licenses: []
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ! '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
none: false
|
105
|
+
requirements:
|
106
|
+
- - ! '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 1.8.24
|
112
|
+
signing_key:
|
113
|
+
specification_version: 3
|
114
|
+
summary: Convenience classes to make using the databasedotcom gem even easier
|
115
|
+
test_files: []
|