apidone-client 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/apidone +0 -0
- data/lib/apidone-client.rb +1 -1
- data/lib/apidone-client/cli.rb +6 -4
- data/lib/apidone-client/connection.rb +5 -7
- data/lib/apidone-client/resource.rb +24 -0
- data/lib/apidone-client/version.rb +1 -1
- data/spec/apidone-client/connection_spec.rb +8 -8
- data/spec/apidone-client/resource_spec.rb +14 -0
- metadata +66 -96
data/bin/apidone
CHANGED
File without changes
|
data/lib/apidone-client.rb
CHANGED
data/lib/apidone-client/cli.rb
CHANGED
@@ -27,7 +27,7 @@ module Apidone
|
|
27
27
|
method_option :domain, :aliases => "-d", :desc => "set domain", :required => true
|
28
28
|
def create(resource)
|
29
29
|
connection(options[:domain])
|
30
|
-
puts @c.create(resource, options[:data])
|
30
|
+
puts @c.create(resource, options[:data]).data
|
31
31
|
end
|
32
32
|
|
33
33
|
map %w(--update -u) => 'update'
|
@@ -37,7 +37,7 @@ module Apidone
|
|
37
37
|
method_option :id, :desc => "set id", :required => true
|
38
38
|
def update(resource)
|
39
39
|
connection(options[:domain])
|
40
|
-
puts @c.update(resource, options[:id], options[:data])
|
40
|
+
puts @c.update(resource, options[:id], options[:data]).data
|
41
41
|
end
|
42
42
|
|
43
43
|
map %w(--destroy -d) => 'delete'
|
@@ -55,7 +55,9 @@ module Apidone
|
|
55
55
|
method_option :domain, :aliases => "-d", :desc => "set domain", :required => true
|
56
56
|
def list(resource)
|
57
57
|
connection(options[:domain])
|
58
|
-
|
58
|
+
@c.list(resource).each do |res|
|
59
|
+
puts res.data
|
60
|
+
end
|
59
61
|
end
|
60
62
|
|
61
63
|
map %w(--show -s) => 'show'
|
@@ -64,7 +66,7 @@ module Apidone
|
|
64
66
|
method_option :id, :desc => "set id", :required => true
|
65
67
|
def show(resource)
|
66
68
|
connection(options[:domain])
|
67
|
-
puts @c.show(resource, options[:id])
|
69
|
+
puts @c.show(resource, options[:id]).data
|
68
70
|
end
|
69
71
|
|
70
72
|
end
|
@@ -22,32 +22,30 @@ module Apidone
|
|
22
22
|
|
23
23
|
def create(name, data = {})
|
24
24
|
response = @conn.post "/#{name}", data
|
25
|
-
|
26
25
|
if response.status == 201
|
27
26
|
json_response = JSON.parse(response.body)
|
28
27
|
data[:id] = json_response["id"]
|
29
28
|
end
|
30
|
-
data
|
29
|
+
show(name, data[:id])
|
31
30
|
end
|
32
31
|
|
33
32
|
def update(name, id, data = {})
|
34
33
|
response = @conn.put "/#{name}/#{id}", data
|
35
|
-
|
36
34
|
if response.status == 201
|
37
35
|
json_response = JSON.parse(response.body)
|
38
36
|
end
|
39
|
-
|
40
|
-
data
|
37
|
+
Apidone::Client::Resource.new data
|
41
38
|
end
|
42
39
|
|
43
40
|
def list(name)
|
44
41
|
response = @conn.get "/#{name}"
|
45
|
-
JSON.parse response.body
|
42
|
+
collection = JSON.parse response.body
|
43
|
+
collection.collect{|o| Apidone::Client::Resource.new(o)}
|
46
44
|
end
|
47
45
|
|
48
46
|
def show(name, id)
|
49
47
|
response = @conn.get("/#{name}/#{id}")
|
50
|
-
JSON.parse response.body
|
48
|
+
Apidone::Client::Resource.new(JSON.parse response.body)
|
51
49
|
end
|
52
50
|
|
53
51
|
def delete(name , id)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Apidone
|
2
|
+
module Client
|
3
|
+
class Resource
|
4
|
+
|
5
|
+
attr_reader :data
|
6
|
+
def initialize(data ={})
|
7
|
+
@data = data
|
8
|
+
meta_fields(data)
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
def meta_fields(data)
|
13
|
+
data.keys.each do |key|
|
14
|
+
instance_eval <<-RUBY
|
15
|
+
def #{key}
|
16
|
+
"#{data[key]}"
|
17
|
+
end
|
18
|
+
RUBY
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -16,7 +16,7 @@ describe "Connection" do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should be hash" do
|
19
|
-
@response.class.should ==
|
19
|
+
@response.class.should == Apidone::Client::Resource
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should not be blank" do
|
@@ -29,15 +29,15 @@ describe "Connection" do
|
|
29
29
|
before :each do
|
30
30
|
@list = @c.list("lenguajes")
|
31
31
|
@rand_num = rand(100)
|
32
|
-
@response = @c.update("lenjuages", "#{@list.first
|
32
|
+
@response = @c.update("lenjuages", "#{@list.first.id}", data = {:age=> @rand_num })
|
33
33
|
end
|
34
34
|
|
35
35
|
it "response should be hash" do
|
36
|
-
@response.class.should ==
|
36
|
+
@response.class.should == Apidone::Client::Resource
|
37
37
|
end
|
38
38
|
|
39
39
|
it "response should id" do
|
40
|
-
@response
|
40
|
+
@response.age.to_i.should == @rand_num
|
41
41
|
end
|
42
42
|
|
43
43
|
end
|
@@ -45,7 +45,7 @@ describe "Connection" do
|
|
45
45
|
describe "when delete reosurce" do
|
46
46
|
before :each do
|
47
47
|
@list = @c.list("lenguajes")
|
48
|
-
@id = @list.last
|
48
|
+
@id = @list.last.id
|
49
49
|
@deleted= @c.delete("lenguajes", @id )
|
50
50
|
end
|
51
51
|
|
@@ -55,7 +55,7 @@ describe "Connection" do
|
|
55
55
|
|
56
56
|
it "should not include the id" do
|
57
57
|
@list = @c.list("lenguajes")
|
58
|
-
@list.map{|o| o
|
58
|
+
@list.map{ |o| o.id }.should_not include(@id)
|
59
59
|
end
|
60
60
|
|
61
61
|
end
|
@@ -63,12 +63,12 @@ describe "Connection" do
|
|
63
63
|
describe "when show resource" do
|
64
64
|
before :each do
|
65
65
|
@list = @c.list("lenguajes")
|
66
|
-
@id = @list.last
|
66
|
+
@id = @list.last.id
|
67
67
|
@resource = @c.show("lenguajes", @id )
|
68
68
|
end
|
69
69
|
|
70
70
|
it "should find something" do
|
71
|
-
@resource.should_not
|
71
|
+
@resource.should_not be_nil
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe "Resource" do
|
4
|
+
before :each do
|
5
|
+
@resource = Apidone::Client::Resource.new({:name=>"mike", :id=>"134234", :age=>23})
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should have created methods" do
|
9
|
+
@resource.methods.include?("name".to_sym).should be_true
|
10
|
+
@resource.methods.include?("id".to_sym).should be_true
|
11
|
+
@resource.methods.include?("age".to_sym).should be_true
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
metadata
CHANGED
@@ -1,108 +1,83 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: apidone-client
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 2
|
10
|
-
version: 0.0.2
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Miguel Michelson
|
14
9
|
- Luis Mancilla
|
15
10
|
- Daniel Guajardo
|
16
|
-
-
|
11
|
+
- Daniel Gutiérrez
|
17
12
|
- Magno Cardona
|
18
13
|
autorequire:
|
19
14
|
bindir: bin
|
20
15
|
cert_chain: []
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
- !ruby/object:Gem::Dependency
|
16
|
+
date: 2012-10-23 00:00:00.000000000 Z
|
17
|
+
dependencies:
|
18
|
+
- !ruby/object:Gem::Dependency
|
25
19
|
name: thor
|
26
|
-
|
27
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
requirement: &70290391062860 !ruby/object:Gem::Requirement
|
28
21
|
none: false
|
29
|
-
requirements:
|
30
|
-
- -
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
|
33
|
-
segments:
|
34
|
-
- 0
|
35
|
-
version: "0"
|
22
|
+
requirements:
|
23
|
+
- - ! '>='
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '0'
|
36
26
|
type: :runtime
|
37
|
-
version_requirements: *id001
|
38
|
-
- !ruby/object:Gem::Dependency
|
39
|
-
name: faraday
|
40
27
|
prerelease: false
|
41
|
-
|
28
|
+
version_requirements: *70290391062860
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: faraday
|
31
|
+
requirement: &70290391062360 !ruby/object:Gem::Requirement
|
42
32
|
none: false
|
43
|
-
requirements:
|
44
|
-
- -
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
|
47
|
-
segments:
|
48
|
-
- 0
|
49
|
-
version: "0"
|
33
|
+
requirements:
|
34
|
+
- - ! '>='
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
50
37
|
type: :runtime
|
51
|
-
version_requirements: *id002
|
52
|
-
- !ruby/object:Gem::Dependency
|
53
|
-
name: json
|
54
38
|
prerelease: false
|
55
|
-
|
39
|
+
version_requirements: *70290391062360
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: json
|
42
|
+
requirement: &70290391061720 !ruby/object:Gem::Requirement
|
56
43
|
none: false
|
57
|
-
requirements:
|
58
|
-
- -
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
|
61
|
-
segments:
|
62
|
-
- 0
|
63
|
-
version: "0"
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
64
48
|
type: :runtime
|
65
|
-
version_requirements: *id003
|
66
|
-
- !ruby/object:Gem::Dependency
|
67
|
-
name: bundler
|
68
49
|
prerelease: false
|
69
|
-
|
50
|
+
version_requirements: *70290391061720
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
name: bundler
|
53
|
+
requirement: &70290391061080 !ruby/object:Gem::Requirement
|
70
54
|
none: false
|
71
|
-
requirements:
|
72
|
-
- -
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
|
75
|
-
segments:
|
76
|
-
- 0
|
77
|
-
version: "0"
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
78
59
|
type: :development
|
79
|
-
version_requirements: *id004
|
80
|
-
- !ruby/object:Gem::Dependency
|
81
|
-
name: rspec
|
82
60
|
prerelease: false
|
83
|
-
|
61
|
+
version_requirements: *70290391061080
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec
|
64
|
+
requirement: &70290391060220 !ruby/object:Gem::Requirement
|
84
65
|
none: false
|
85
|
-
requirements:
|
66
|
+
requirements:
|
86
67
|
- - ~>
|
87
|
-
- !ruby/object:Gem::Version
|
88
|
-
hash: 23
|
89
|
-
segments:
|
90
|
-
- 2
|
91
|
-
- 6
|
92
|
-
- 0
|
68
|
+
- !ruby/object:Gem::Version
|
93
69
|
version: 2.6.0
|
94
70
|
type: :development
|
95
|
-
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: *70290391060220
|
96
73
|
description: Apidone.com ruby api client
|
97
|
-
email:
|
74
|
+
email:
|
98
75
|
- miguelmichelson@gmail.com
|
99
|
-
executables:
|
76
|
+
executables:
|
100
77
|
- apidone
|
101
78
|
extensions: []
|
102
|
-
|
103
79
|
extra_rdoc_files: []
|
104
|
-
|
105
|
-
files:
|
80
|
+
files:
|
106
81
|
- .gitignore
|
107
82
|
- Gemfile
|
108
83
|
- LICENSE.txt
|
@@ -113,42 +88,37 @@ files:
|
|
113
88
|
- lib/apidone-client.rb
|
114
89
|
- lib/apidone-client/cli.rb
|
115
90
|
- lib/apidone-client/connection.rb
|
91
|
+
- lib/apidone-client/resource.rb
|
116
92
|
- lib/apidone-client/version.rb
|
117
93
|
- spec/apidone-client/connection_spec.rb
|
94
|
+
- spec/apidone-client/resource_spec.rb
|
118
95
|
- spec/spec_helper.rb
|
119
96
|
homepage: http://apidone.com
|
120
97
|
licenses: []
|
121
|
-
|
122
98
|
post_install_message:
|
123
99
|
rdoc_options: []
|
124
|
-
|
125
|
-
require_paths:
|
100
|
+
require_paths:
|
126
101
|
- lib
|
127
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
103
|
none: false
|
129
|
-
requirements:
|
130
|
-
- -
|
131
|
-
- !ruby/object:Gem::Version
|
132
|
-
|
133
|
-
|
134
|
-
- 0
|
135
|
-
version: "0"
|
136
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ! '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
109
|
none: false
|
138
|
-
requirements:
|
139
|
-
- -
|
140
|
-
- !ruby/object:Gem::Version
|
141
|
-
|
142
|
-
segments:
|
143
|
-
- 0
|
144
|
-
version: "0"
|
110
|
+
requirements:
|
111
|
+
- - ! '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
145
114
|
requirements: []
|
146
|
-
|
147
115
|
rubyforge_project:
|
148
|
-
rubygems_version: 1.8.
|
116
|
+
rubygems_version: 1.8.15
|
149
117
|
signing_key:
|
150
118
|
specification_version: 3
|
151
|
-
summary: Apidone ruby client is a simple client for apidone.com, this library was
|
152
|
-
|
119
|
+
summary: Apidone ruby client is a simple client for apidone.com, this library was
|
120
|
+
made in the context of coding (ruby) dojo. oct 2012
|
121
|
+
test_files:
|
153
122
|
- spec/apidone-client/connection_spec.rb
|
123
|
+
- spec/apidone-client/resource_spec.rb
|
154
124
|
- spec/spec_helper.rb
|