grosser-concat_rpc 0.1.1
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/README.markdown +28 -0
- data/Rakefile +34 -0
- data/concat_rpc.gemspec +34 -0
- data/init.rb +1 -0
- data/lib/concat_rpc/person.rb +52 -0
- data/lib/concat_rpc.rb +13 -0
- data/spec/concat_rpc_spec.rb +77 -0
- data/spec/spec_helper.rb +24 -0
- metadata +76 -0
data/README.markdown
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
Concat API
|
2
|
+
==========
|
3
|
+
- AR-like Concat - Person abstraction
|
4
|
+
|
5
|
+
INSTALL
|
6
|
+
=======
|
7
|
+
|
8
|
+
sudo gem install grosser-concat_rpc
|
9
|
+
|
10
|
+
USAGE
|
11
|
+
=====
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'concat_rpc'
|
15
|
+
ConcatRPC.url = 'http://USERNAME:PASSWORD@HOST/concat/rpc/index'
|
16
|
+
|
17
|
+
p = ConcatRPC::Person.new(:cmail=>'my email',:gender=>2)
|
18
|
+
p.save!
|
19
|
+
p.pemail = 'my personal mail'
|
20
|
+
p.save!.id == ConcatRPC::Person.find_by_text(p.cemail).id
|
21
|
+
ConcatRPC::Person.untag(p.id,'Foo')
|
22
|
+
ConcatRPC::Person.tag(p.id,'Bar')
|
23
|
+
|
24
|
+
AUTHOR
|
25
|
+
======
|
26
|
+
Michael Grosser
|
27
|
+
grosser.michael@gmail.com
|
28
|
+
Hereby placed under public domain, do what you want, just do not hold me accountable...
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spec'
|
3
|
+
|
4
|
+
desc 'Default: run spec.'
|
5
|
+
task :default => :spec
|
6
|
+
|
7
|
+
desc "Run all specs in spec directory"
|
8
|
+
task :spec do |t|
|
9
|
+
options = "--colour --format progress --loadby --reverse"
|
10
|
+
files = FileList['spec/**/*_spec.rb']
|
11
|
+
system("spec #{options} #{files}")
|
12
|
+
end
|
13
|
+
|
14
|
+
require 'rubygems'
|
15
|
+
require 'rake'
|
16
|
+
require 'echoe'
|
17
|
+
|
18
|
+
Echoe.new('concat_rpc', '0.1.1') do |p|
|
19
|
+
p.description = "Api for 20Sec Concat - Contact managing"
|
20
|
+
p.url = "http://github.com/grosser/concat_rpc"
|
21
|
+
p.author = "Michael Grosser"
|
22
|
+
p.email = "grosser.michael@gmail.com"
|
23
|
+
p.ignore_pattern = ["tmp/*", "script/*", "spec/credentials", "nbproject/*"]
|
24
|
+
p.dependencies = ['activesupport']
|
25
|
+
p.development_dependencies = []
|
26
|
+
end
|
27
|
+
|
28
|
+
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
|
29
|
+
|
30
|
+
task :update_gemspec do
|
31
|
+
puts "updating..."
|
32
|
+
`rake manifest`
|
33
|
+
`rake build_gemspec`
|
34
|
+
end
|
data/concat_rpc.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{concat_rpc}
|
5
|
+
s.version = "0.1.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Michael Grosser"]
|
9
|
+
s.date = %q{2008-12-31}
|
10
|
+
s.description = %q{Api for 20Sec Concat - Contact managing}
|
11
|
+
s.email = %q{grosser.michael@gmail.com}
|
12
|
+
s.extra_rdoc_files = ["lib/concat_rpc/person.rb", "lib/concat_rpc.rb", "README.markdown"]
|
13
|
+
s.files = ["Manifest", "lib/concat_rpc/person.rb", "lib/concat_rpc.rb", "spec/spec_helper.rb", "spec/concat_rpc_spec.rb", "init.rb", "Rakefile", "README.markdown", "concat_rpc.gemspec"]
|
14
|
+
s.has_rdoc = true
|
15
|
+
s.homepage = %q{http://github.com/grosser/concat_rpc}
|
16
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Concat_rpc", "--main", "README.markdown"]
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
s.rubyforge_project = %q{concat_rpc}
|
19
|
+
s.rubygems_version = %q{1.3.1}
|
20
|
+
s.summary = %q{Api for 20Sec Concat - Contact managing}
|
21
|
+
|
22
|
+
if s.respond_to? :specification_version then
|
23
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
24
|
+
s.specification_version = 2
|
25
|
+
|
26
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
27
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 0"])
|
28
|
+
else
|
29
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
30
|
+
end
|
31
|
+
else
|
32
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
33
|
+
end
|
34
|
+
end
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'ar_merge'
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module ConcatRPC
|
2
|
+
class Person
|
3
|
+
require 'activesupport'
|
4
|
+
class_inheritable_accessor :defaults
|
5
|
+
self.defaults = {'gender'=>0,'lname'=>'UNKNOWN'}
|
6
|
+
|
7
|
+
def self.find(id)
|
8
|
+
new(ConcatRPC.show_person(id))
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.find_by_text(text)
|
12
|
+
person = ConcatRPC.find_person(text).first
|
13
|
+
return unless person
|
14
|
+
find(person['id'])
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.tag(id,tag)
|
18
|
+
ConcatRPC.set_tag(id,tag)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.untag(id,tag)
|
22
|
+
ConcatRPC.unset_tag(id,tag)
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize(data={})
|
26
|
+
@data = data.stringify_keys
|
27
|
+
end
|
28
|
+
|
29
|
+
def save!
|
30
|
+
self.id = ConcatRPC.create_person(self.class.defaults.merge(@data))
|
31
|
+
self
|
32
|
+
end
|
33
|
+
|
34
|
+
def id
|
35
|
+
@data['id'].to_i
|
36
|
+
end
|
37
|
+
|
38
|
+
def method_missing(name,value=nil)
|
39
|
+
name = name.to_s
|
40
|
+
if name =~ /(.*)=$/
|
41
|
+
@data[$1]=value
|
42
|
+
else
|
43
|
+
return @data[name] if @data.key?(name)
|
44
|
+
super
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def respond_to?(name)
|
49
|
+
@data.key?(name.to_s) || super
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/concat_rpc.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
require File.expand_path("spec_helper", File.dirname(__FILE__))
|
2
|
+
credentials = open(File.join(File.dirname(__FILE__),'credentials'))
|
3
|
+
URL = "http://#{credentials}@monty/concat/rpc/index"
|
4
|
+
|
5
|
+
include ConcatRPC
|
6
|
+
|
7
|
+
describe ConcatRPC do
|
8
|
+
PERSON_ID = 77487
|
9
|
+
PERSON_EMAIL = 'nenew@watchothers.com'
|
10
|
+
before do
|
11
|
+
ConcatRPC.url = URL
|
12
|
+
end
|
13
|
+
it("does not crash"){}
|
14
|
+
describe :find do
|
15
|
+
it "finds by id" do
|
16
|
+
Person.find(PERSON_ID).id.should == PERSON_ID
|
17
|
+
end
|
18
|
+
end
|
19
|
+
describe :find_by_text do
|
20
|
+
it "finds a person by email" do
|
21
|
+
Person.find_by_text(PERSON_EMAIL).id.should == PERSON_ID
|
22
|
+
end
|
23
|
+
end
|
24
|
+
describe 'tagging' do
|
25
|
+
before do
|
26
|
+
Person.untag(PERSON_ID,'testing_tagging')
|
27
|
+
end
|
28
|
+
it "tags a person" do
|
29
|
+
Person.tag(PERSON_ID ,'testing_tagging')
|
30
|
+
Person.find(PERSON_ID).tags_as_text.should =~ /testing_tagging/
|
31
|
+
end
|
32
|
+
it "untags a person" do
|
33
|
+
Person.tag(PERSON_ID ,'testing_tagging')
|
34
|
+
Person.untag(PERSON_ID ,'testing_tagging')
|
35
|
+
Person.find(PERSON_ID).tags_as_text.should_not =~ /testing_tagging/
|
36
|
+
end
|
37
|
+
it "untags a duplicate taged person" do
|
38
|
+
Person.tag(PERSON_ID ,'testing_tagging')
|
39
|
+
Person.tag(PERSON_ID ,'testing_tagging')
|
40
|
+
Person.tag(PERSON_ID ,'testing_tagging')
|
41
|
+
Person.untag(PERSON_ID ,'testing_tagging')
|
42
|
+
Person.find(PERSON_ID).tags_as_text.should_not =~ /testing_tagging/
|
43
|
+
end
|
44
|
+
end
|
45
|
+
describe :save! do
|
46
|
+
it "can save a empty record and stores the id" do
|
47
|
+
Person.new().save!.id.should > PERSON_ID
|
48
|
+
end
|
49
|
+
it "creates a person using defaults" do
|
50
|
+
p = Person.new()
|
51
|
+
defaults = Person.defaults
|
52
|
+
Person.stubs(:defaults).returns(defaults.merge(:cemail=>'ydadada@sdsds.dd'))
|
53
|
+
p.save!
|
54
|
+
Person.find(p.id).cemail.should == "ydadada@sdsds.dd"
|
55
|
+
end
|
56
|
+
it "creates a person with attributes" do
|
57
|
+
p = Person.new(:cemail=>"hans_peter@fuu.de")
|
58
|
+
p.save!
|
59
|
+
Person.find(p.id).cemail.should == "hans_peter@fuu.de"
|
60
|
+
end
|
61
|
+
it "does not overwrite attributes with defaults" do
|
62
|
+
p = Person.new(:cemail=>"hans_peter@fuu.de",:gender=>2)
|
63
|
+
p.save!
|
64
|
+
Person.find(p.id).gender.should == "2"
|
65
|
+
end
|
66
|
+
it "updates an existing person without crreating a new" do
|
67
|
+
person = Person.new.save!
|
68
|
+
lambda{person.save!}.should_not change(person,:id)
|
69
|
+
end
|
70
|
+
it "saves new attributes when updating" do
|
71
|
+
person = Person.new.save!
|
72
|
+
person.cemail = 'asdadaadsas@dssdfddf.dd'
|
73
|
+
person.save!
|
74
|
+
Person.find(person.id).cemail.should == 'asdadaadsas@dssdfddf.dd'
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# ---- requirements
|
2
|
+
require 'rubygems'
|
3
|
+
require 'spec'
|
4
|
+
require 'mocha'
|
5
|
+
|
6
|
+
$LOAD_PATH << File.expand_path("../lib", File.dirname(__FILE__))
|
7
|
+
require 'concat_rpc'
|
8
|
+
|
9
|
+
# ---- bugfix
|
10
|
+
#`exit?': undefined method `run?' for Test::Unit:Module (NoMethodError)
|
11
|
+
#can be solved with require test/unit but this will result in extra test-output
|
12
|
+
module Test
|
13
|
+
module Unit
|
14
|
+
def self.run?
|
15
|
+
true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
# ---- rspec
|
22
|
+
Spec::Runner.configure do |config|
|
23
|
+
config.mock_with :mocha
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: grosser-concat_rpc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael Grosser
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-12-31 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: activesupport
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: "0"
|
23
|
+
version:
|
24
|
+
description: Api for 20Sec Concat - Contact managing
|
25
|
+
email: grosser.michael@gmail.com
|
26
|
+
executables: []
|
27
|
+
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files:
|
31
|
+
- lib/concat_rpc/person.rb
|
32
|
+
- lib/concat_rpc.rb
|
33
|
+
- README.markdown
|
34
|
+
files:
|
35
|
+
- Manifest
|
36
|
+
- lib/concat_rpc/person.rb
|
37
|
+
- lib/concat_rpc.rb
|
38
|
+
- spec/spec_helper.rb
|
39
|
+
- spec/concat_rpc_spec.rb
|
40
|
+
- init.rb
|
41
|
+
- Rakefile
|
42
|
+
- README.markdown
|
43
|
+
- concat_rpc.gemspec
|
44
|
+
has_rdoc: true
|
45
|
+
homepage: http://github.com/grosser/concat_rpc
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options:
|
48
|
+
- --line-numbers
|
49
|
+
- --inline-source
|
50
|
+
- --title
|
51
|
+
- Concat_rpc
|
52
|
+
- --main
|
53
|
+
- README.markdown
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "1.2"
|
67
|
+
version:
|
68
|
+
requirements: []
|
69
|
+
|
70
|
+
rubyforge_project: concat_rpc
|
71
|
+
rubygems_version: 1.2.0
|
72
|
+
signing_key:
|
73
|
+
specification_version: 2
|
74
|
+
summary: Api for 20Sec Concat - Contact managing
|
75
|
+
test_files: []
|
76
|
+
|