apidone-client 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+ #source :gemcutter
3
+
4
+
5
+ #gem "thor", :git=>"git://github.com/wycats/thor.git"
6
+ #gem "faraday", :git=>"git://github.com/technoweenie/faraday.git"
7
+ #gem "json", :git=>"git://github.com/flori/json.git"
8
+ #gem "rspec"
9
+ # Specify your gem's dependencies in apidone-client.gemspec
10
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Miguel Michelson
2
+
3
+ MIT License
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,77 @@
1
+ # Apidone::Client
2
+
3
+ ApiDone ruby client.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'apidone-client'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install apidone-client
18
+
19
+ ## Usage
20
+
21
+ ### Usage in scripts
22
+
23
+ #### init connection:
24
+
25
+ @conn = Apidone::Client::Connection.new("dojoruby")
26
+
27
+ #### Create a resource:
28
+
29
+ @c.create("lenguajes")
30
+
31
+ #### List resources
32
+
33
+ @c.list("lenguajes")
34
+
35
+ #### Edit , delete & show resources:
36
+
37
+ @c.update("lenjuages", "someid", {:name=>"ruby", :versions=>["1.8.7", "Ree", "rbx"]})
38
+
39
+ @c.delete("lenjuages", "someid")
40
+
41
+ @c.show("lenjuages", "someid")
42
+
43
+ ## Command line
44
+
45
+ #### create
46
+
47
+ $ apidone create art -d=artenlinea --data=foo:bar
48
+
49
+ #### list
50
+
51
+ $ apidone list art -d=artenlinea
52
+
53
+ #### update
54
+
55
+ $ apidone update art -d=artenlinea --id=some_id --data=foo:bar_updated
56
+
57
+ #### delete
58
+
59
+ $ apidone show art -d=artenlinea --id=some_id
60
+
61
+ #### delete
62
+
63
+ $ apidone delete art -d=artenlinea --id=some_id
64
+
65
+
66
+ #### command help
67
+
68
+ $ apidone help [create, edit, update, list, show ]
69
+
70
+
71
+ ## Contributing
72
+
73
+ 1. Fork it
74
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
75
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
76
+ 4. Push to the branch (`git push origin my-new-feature`)
77
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'apidone-client/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "apidone-client"
8
+ gem.version = Apidone::Client::VERSION
9
+ gem.authors = ["Miguel Michelson", "Luis Mancilla", "Daniel Guajardo"]
10
+ gem.email = ["miguelmichelson@gmail.com"]
11
+ gem.description = "Apidone.com ruby api client"
12
+ gem.summary = "Apidone ruby client is a simple client."
13
+ gem.homepage = "http://apidone.com"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_runtime_dependency("thor")
21
+ gem.add_runtime_dependency("faraday")
22
+ gem.add_runtime_dependency("json")
23
+
24
+ gem.add_development_dependency(%q<bundler>)
25
+ gem.add_development_dependency(%q<rspec>, ["~> 2.6.0"])
26
+
27
+
28
+
29
+ end
data/bin/apidone ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ require 'thor'
3
+ require 'apidone-client'
4
+
5
+ Apidone::Client::CLI.start
@@ -0,0 +1,15 @@
1
+ require 'pathname'
2
+ require "apidone-client/version"
3
+ require 'faraday'
4
+ require 'json'
5
+
6
+ module Apidone
7
+ module Client
8
+
9
+ ROOT_PATH = Pathname(__FILE__).dirname.expand_path
10
+
11
+ autoload :CLI, 'apidone-client/cli.rb'
12
+ autoload :Connection, 'apidone-client/connection.rb'
13
+
14
+ end
15
+ end
@@ -0,0 +1,72 @@
1
+ require "thor/group"
2
+
3
+ module Apidone
4
+ module Client
5
+
6
+ class CLI < Thor
7
+ include Thor::Actions
8
+
9
+ no_tasks{
10
+
11
+ def connection(domain)
12
+ @c = Apidone::Client::Connection.new(domain)
13
+ end
14
+
15
+ }
16
+
17
+ ### TODO: When these commands list grows big, we need to move them into a seperate commands.rb file
18
+ map %w(--version -v) => 'info'
19
+ desc "info", "information about ApiDone::Client."
20
+ def info
21
+ say "Version #{::Apidone::Client::VERSION}"
22
+ end
23
+
24
+ map %w(--create -c) => 'create'
25
+ desc "create", "Creates ApiDone resource"
26
+ method_option :data, :type => :hash, :default => {}, :required => true
27
+ method_option :domain, :aliases => "-d", :desc => "set domain", :required => true
28
+ def create(resource)
29
+ connection(options[:domain])
30
+ puts @c.create(resource, options[:data])
31
+ end
32
+
33
+ map %w(--update -u) => 'update'
34
+ desc "update", "Updates ApiDone resource"
35
+ method_option :data, :type => :hash, :default => {}, :required => true
36
+ method_option :domain, :aliases => "-d", :desc => "set domain", :required => true
37
+ method_option :id, :desc => "set id", :required => true
38
+ def update(resource)
39
+ connection(options[:domain])
40
+ puts @c.update(resource, options[:id], options[:data])
41
+ end
42
+
43
+ map %w(--destroy -d) => 'delete'
44
+ desc "delete", "Delete ApiDone resource"
45
+ method_option :data, :type => :hash, :default => {}, :required => true
46
+ method_option :domain, :aliases => "-d", :desc => "set domain", :required => true
47
+ method_option :id, :desc => "set id", :required => true
48
+ def delete(resource)
49
+ connection(options[:domain])
50
+ puts @c.update(resource, options[:id])
51
+ end
52
+
53
+ map %w(--list -l) => 'list'
54
+ desc "list", "List ApiDone resource"
55
+ method_option :domain, :aliases => "-d", :desc => "set domain", :required => true
56
+ def list(resource)
57
+ connection(options[:domain])
58
+ puts @c.list(resource)
59
+ end
60
+
61
+ map %w(--show -s) => 'show'
62
+ desc "show", "Show ApiDone resource"
63
+ method_option :domain, :aliases => "-d", :desc => "set domain", :required => true
64
+ method_option :id, :desc => "set id", :required => true
65
+ def show(resource)
66
+ connection(options[:domain])
67
+ puts @c.show(resource, options[:id])
68
+ end
69
+
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,62 @@
1
+ module Apidone
2
+ module Client
3
+ class Connection
4
+
5
+ API_DONE_URL = "apidone.com"
6
+
7
+ attr_accessor :subdomain, :conn
8
+
9
+ def initialize(subdomain)
10
+ @subdomain = subdomain
11
+
12
+ @conn = Faraday.new(:url => self.endpoint_url) do |faraday|
13
+ faraday.request :url_encoded # form-encode POST params
14
+ #faraday.response :logger # log requests to STDOUT
15
+ faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
16
+ end
17
+ end
18
+
19
+ def endpoint_url
20
+ "http://#{subdomain}.#{API_DONE_URL}"
21
+ end
22
+
23
+ def create(name, data = {})
24
+ response = @conn.post "/#{name}", data
25
+
26
+ if response.status == 201
27
+ json_response = JSON.parse(response.body)
28
+ data[:id] = json_response["id"]
29
+ end
30
+ data
31
+ end
32
+
33
+ def update(name, id, data = {})
34
+ response = @conn.put "/#{name}/#{id}", data
35
+
36
+ if response.status == 201
37
+ json_response = JSON.parse(response.body)
38
+ end
39
+
40
+ data
41
+ end
42
+
43
+ def list(name)
44
+ response = @conn.get "/#{name}"
45
+ JSON.parse response.body
46
+ end
47
+
48
+ def show(name, id)
49
+ response = @conn.get("/#{name}/#{id}")
50
+ JSON.parse response.body
51
+ end
52
+
53
+ def delete(name , id)
54
+ response = @conn.delete "/#{name}/#{id}"
55
+ if response.status == 204
56
+ return true
57
+ end
58
+ end
59
+
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,5 @@
1
+ module Apidone
2
+ module Client
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,75 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "Connection" do
4
+
5
+ before(:each) do
6
+ @c = Apidone::Client::Connection.new("dojoruby")
7
+ end
8
+
9
+ it "should return the base location" do
10
+ @c.class.should == Apidone::Client::Connection
11
+ end
12
+
13
+ describe "when create resource" do
14
+ before :each do
15
+ @response = @c.create("lenguajes")
16
+ end
17
+
18
+ it "should be hash" do
19
+ @response.class.should == Hash
20
+ end
21
+
22
+ it "should not be blank" do
23
+ @response.should_not be_nil
24
+ end
25
+
26
+ end
27
+
28
+ describe "when update resource" do
29
+ before :each do
30
+ @list = @c.list("lenguajes")
31
+ @rand_num = rand(100)
32
+ @response = @c.update("lenjuages", "#{@list.first[:id]}", data = {:age=>@rand_num})
33
+ end
34
+
35
+ it "response should be hash" do
36
+ @response.class.should == Hash
37
+ end
38
+
39
+ it "response should id" do
40
+ @response[:age].should == @rand_num
41
+ end
42
+
43
+ end
44
+
45
+ describe "when delete reosurce" do
46
+ before :each do
47
+ @list = @c.list("lenguajes")
48
+ @id = @list.last["id"]
49
+ @deleted= @c.delete("lenguajes", @id )
50
+ end
51
+
52
+ it "should be true" do
53
+ @deleted.should be_true
54
+ end
55
+
56
+ it "should not include the id" do
57
+ @list = @c.list("lenguajes")
58
+ @list.map{|o| o["id"]}.should_not include(@id)
59
+ end
60
+
61
+ end
62
+
63
+ describe "when show resource" do
64
+ before :each do
65
+ @list = @c.list("lenguajes")
66
+ @id = @list.last["id"]
67
+ @resource = @c.show("lenguajes", @id )
68
+ end
69
+
70
+ it "should find something" do
71
+ @resource.should_not be_empty
72
+ end
73
+ end
74
+
75
+ end
@@ -0,0 +1,5 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib', 'apidone-client'))
2
+ require 'rspec'
3
+ require 'apidone-client'
4
+ require 'faraday'
5
+ require "json"
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: apidone-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Miguel Michelson
9
+ - Luis Mancilla
10
+ - Daniel Guajardo
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2012-10-18 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: thor
18
+ requirement: &70166508110900 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
23
+ version: '0'
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *70166508110900
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: &70166508109800 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: *70166508109800
38
+ - !ruby/object:Gem::Dependency
39
+ name: json
40
+ requirement: &70166508109320 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: *70166508109320
49
+ - !ruby/object:Gem::Dependency
50
+ name: bundler
51
+ requirement: &70166508108880 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: *70166508108880
60
+ - !ruby/object:Gem::Dependency
61
+ name: rspec
62
+ requirement: &70166508108060 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: 2.6.0
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: *70166508108060
71
+ description: Apidone.com ruby api client
72
+ email:
73
+ - miguelmichelson@gmail.com
74
+ executables:
75
+ - apidone
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - .gitignore
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - apidone-client.gemspec
85
+ - bin/apidone
86
+ - lib/apidone-client.rb
87
+ - lib/apidone-client/cli.rb
88
+ - lib/apidone-client/connection.rb
89
+ - lib/apidone-client/version.rb
90
+ - spec/apidone-client/connection_spec.rb
91
+ - spec/spec_helper.rb
92
+ homepage: http://apidone.com
93
+ licenses: []
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 1.8.15
113
+ signing_key:
114
+ specification_version: 3
115
+ summary: Apidone ruby client is a simple client.
116
+ test_files:
117
+ - spec/apidone-client/connection_spec.rb
118
+ - spec/spec_helper.rb