ourkudos 0.0.2

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/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ group :development do
2
+ gem "rspec", "~> 2.3.0"
3
+ gem "bundler", "~> 1.0.0"
4
+ gem "jeweler"
5
+ gem "rcov", ">= 0"
6
+ end
7
+ gem 'nestful'
data/Gemfile.lock ADDED
@@ -0,0 +1,31 @@
1
+ GEM
2
+ specs:
3
+ activesupport (3.0.7)
4
+ diff-lcs (1.1.2)
5
+ git (1.2.5)
6
+ jeweler (1.6.0)
7
+ bundler (~> 1.0.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ nestful (0.0.6)
11
+ activesupport (>= 3.0.0.beta)
12
+ rake (0.8.7)
13
+ rcov (0.9.9)
14
+ rspec (2.3.0)
15
+ rspec-core (~> 2.3.0)
16
+ rspec-expectations (~> 2.3.0)
17
+ rspec-mocks (~> 2.3.0)
18
+ rspec-core (2.3.0)
19
+ rspec-expectations (2.3.0)
20
+ diff-lcs (~> 1.1.2)
21
+ rspec-mocks (2.3.0)
22
+
23
+ PLATFORMS
24
+ ruby
25
+
26
+ DEPENDENCIES
27
+ bundler (~> 1.0.0)
28
+ jeweler
29
+ nestful
30
+ rcov
31
+ rspec (~> 2.3.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Our Kudos
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,6 @@
1
+ = ourkudos
2
+
3
+ Description goes here.
4
+
5
+
6
+
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "ourkudos"
18
+ gem.homepage = "http://ourkudos.com"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{OurKudos client api gem}
21
+ gem.description = %Q{OurKudos client api gem}
22
+ gem.email = "marcin.walczak@gmail.com"
23
+ gem.authors = ["Marcin Walczak"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ require 'rcov/rcovtask'
36
+ Rcov::RcovTask.new do |test|
37
+ test.libs << 'test'
38
+ test.pattern = 'test/**/test_*.rb'
39
+ test.verbose = true
40
+ test.rcov_opts << '--exclude "gems/*"'
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "ourkudos #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.2
@@ -0,0 +1,2 @@
1
+ base_uri: 'http://localhost:3000/api/'
2
+ api_key: 'ihR2v3lzGvlZxsqWxnx8xkiJy7RzPWRXSf3ZfijBLwxhIgFgmCXW3qUyCZ5ZbeQa'
@@ -0,0 +1,112 @@
1
+ require 'nestful'
2
+ module OurKudos
3
+
4
+ class << self
5
+
6
+ #alias method
7
+ def api_key
8
+ OurKudos::Client.api_key
9
+ end
10
+
11
+ #alias methods
12
+ def base_uri
13
+ OurKudos::Client.base_uri
14
+ end
15
+
16
+ #alias method
17
+ def api_key= api_key
18
+ OurKudos::Client.api_key = api_key
19
+ end
20
+
21
+ #alias method
22
+ def base_uri= uri
23
+ OurKudos::Client.base_uri = uri
24
+ end
25
+
26
+ def config_file_path
27
+ File.join File.expand_path(File.dirname(__FILE__)), 'config', 'config.yaml'
28
+ end
29
+
30
+ end
31
+
32
+
33
+
34
+ class Client
35
+
36
+ cattr_accessor :api_key, :base_uri
37
+
38
+ include OurKudos::ResourceEditor
39
+
40
+ #configuration hash
41
+ OurKudosClientOptions = { 'api_key' => nil,
42
+ 'base_uri' => "http://localhost:3000/api/" } if !Object.const_defined? :ClientOptions # :nodoc:
43
+
44
+
45
+ #load settings from yaml file, if file is found
46
+ if File.exists? OurKudos.config_file_path
47
+ config = YAML.load_file OurKudos.config_file_path
48
+ @@base_uri = OurKudosClientOptions['base_uri'] = config['base_uri']
49
+ @@api_key = OurKudosClientOptions['api_key'] = config['api_key']
50
+ end
51
+
52
+ # CLASS METHODS #
53
+ class << self
54
+
55
+ #sets new api key
56
+ def api_key= api_key = nil
57
+ return @@api_key unless api_key
58
+
59
+ @@api_key = OurKudosClientOptions['api_key'] = api_key
60
+ end
61
+
62
+ #sets base url
63
+ def base_uri= base_uri = nil
64
+ return @@base_uri unless base_uri
65
+
66
+ @@base_uri = OurKudosClientOptions['base_uri'] = base_uri
67
+ end
68
+
69
+ end
70
+
71
+ # INSTANCE METHODS #
72
+
73
+ #sets resource to read/edit/delete
74
+ def resource_name= resource
75
+ OurKudos::ResourceEditor.resource_name = resource
76
+ end
77
+
78
+ #displays current resource
79
+ def resource_name
80
+ OurKudos::ResourceEditor.resource_name
81
+ end
82
+
83
+ # general restuful post method - creates an item
84
+ def post(options = {})
85
+ Nestful.post OurKudos.base_uri + options[:path], :params => {:api_key => OurKudos.api_key}.merge(options[:params]),
86
+ :format => :json
87
+ end
88
+
89
+ # retrieves item
90
+ def get(options = {})
91
+ Nestful.get OurKudos.base_uri + options[:path], :params => {:api_key => OurKudos.api_key}.merge(options[:params]),
92
+ :format => :json
93
+ end
94
+
95
+ # updates item
96
+ def put(options = {})
97
+ Nestful.put OurKudos.base_uri + options[:path], :params => {:api_key => OurKudos.api_key}.merge(options[:params]),
98
+ :format => :json
99
+ end
100
+
101
+ # deletes item
102
+ def delete(options = {})
103
+ Nestful.delete OurKudos.base_uri + options[:path], :params => {:api_key => OurKudos.api_key}.merge(options[:params]),
104
+ :format => :json
105
+ end
106
+
107
+
108
+
109
+
110
+
111
+ end
112
+ end
@@ -0,0 +1,30 @@
1
+ module OurKudos
2
+ module ResourceEditor
3
+
4
+ def self.resource_name= name
5
+ @@resource_name = name
6
+ end
7
+
8
+ def self.resource_name
9
+ @@resource_name
10
+ end
11
+
12
+ def create fields = {}
13
+ post(:path => "#{@@resource_name}s.json", :params => {:user => fields})
14
+ end
15
+
16
+ def edit(id, fields = {})
17
+ put(:path => "#{@@resource_name}s/#{id.to_s}.json", :params => {:user => fields })
18
+ end
19
+
20
+ def show id
21
+ get(:path => "#{@@resource_name}s/#{id.to_s}.json", :params => {})
22
+ end
23
+
24
+ def delete id
25
+ delete(:path => "#{@@resource_name}s/#{id.to_s}.json", :params => {})
26
+ end
27
+
28
+
29
+ end
30
+ end
@@ -0,0 +1,23 @@
1
+ module OurKudos
2
+ class ResponseCodes
3
+
4
+ CODES_MAP = {
5
+ :I1 => 'User created',
6
+ :I2 => 'User updated',
7
+ :E1 => 'No such api key',
8
+ :E2 => "Api key expired",
9
+ :E3 => 'This app / site is blocked',
10
+ :E4 => "Cannot save this user",
11
+ :E5 => 'Server error',
12
+ :E6 => 'Unable to update user',
13
+ :E7 => "Unable to process request, server responded with error",
14
+ :E8 => "No such record",
15
+ :E9 => "No such action / resource"
16
+ }
17
+
18
+ def self.[](code)
19
+ CODES_MAP[code]
20
+ end
21
+
22
+ end
23
+ end
data/lib/ourkudos.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'ourkudos/our_kudos'
2
+ require 'ourkudos/response_codes'
3
+ require 'ourkudos/resource_editor'
data/ourkudos.gemspec ADDED
@@ -0,0 +1,66 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{ourkudos}
8
+ s.version = "0.0.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = [%q{Marcin Walczak}]
12
+ s.date = %q{2011-05-05}
13
+ s.description = %q{OurKudos client api gem}
14
+ s.email = %q{marcin.walczak@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/ourkudos.rb",
28
+ "lib/ourkudos/config/config.yaml",
29
+ "lib/ourkudos/our_kudos.rb",
30
+ "lib/ourkudos/resource_editor.rb",
31
+ "lib/ourkudos/response_codes.rb",
32
+ "ourkudos.gemspec",
33
+ "spec/our_kudos_spec.rb",
34
+ "spec/spec_helper.rb"
35
+ ]
36
+ s.homepage = %q{http://ourkudos.com}
37
+ s.licenses = [%q{MIT}]
38
+ s.require_paths = [%q{lib}]
39
+ s.rubygems_version = %q{1.8.0}
40
+ s.summary = %q{OurKudos client api gem}
41
+
42
+ if s.respond_to? :specification_version then
43
+ s.specification_version = 3
44
+
45
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
+ s.add_runtime_dependency(%q<nestful>, [">= 0"])
47
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
48
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
49
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
50
+ s.add_development_dependency(%q<rcov>, [">= 0"])
51
+ else
52
+ s.add_dependency(%q<nestful>, [">= 0"])
53
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
54
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
55
+ s.add_dependency(%q<jeweler>, [">= 0"])
56
+ s.add_dependency(%q<rcov>, [">= 0"])
57
+ end
58
+ else
59
+ s.add_dependency(%q<nestful>, [">= 0"])
60
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
61
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
62
+ s.add_dependency(%q<jeweler>, [">= 0"])
63
+ s.add_dependency(%q<rcov>, [">= 0"])
64
+ end
65
+ end
66
+
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe OurKudos::Client do
4
+ context "#initialize" do
5
+
6
+ it "returns OurKudos::Client instance" do
7
+ instance = OurKudos::Client.new
8
+ instance.should be_a(OurKudos::Client)
9
+ end
10
+
11
+ it 'should be able to assign an api key' do
12
+ key = 'new_api_key'
13
+ OurKudos::Client.respond_to?("api_key=").should_not be_false
14
+ OurKudos::Client.api_key = key
15
+ OurKudos::Client.api_key.should == key && OurKudos.api_key == key
16
+ end
17
+
18
+ it 'should be able to assign base_url ' do
19
+ uri = 'http://our-kudos.com/api'
20
+ OurKudos::Client.respond_to?("base_uri=").should_not be_false
21
+ OurKudos::Client.base_uri = uri
22
+ OurKudos::Client.base_uri.should == uri && OurKudos.base_uri == uri
23
+ end
24
+
25
+ it 'should be able to get config file path' do
26
+ OurKudos.config_file_path.should_not be_nil
27
+ end
28
+
29
+ end
30
+
31
+ context "given an instance" do
32
+ let(:client) { OurKudos::Client.new }
33
+
34
+ it 'should be able to send create an account' do
35
+ client.respond_to?("create_account").should_not be_nil
36
+
37
+ end
38
+
39
+ end
40
+
41
+ end
42
+
43
+
44
+
@@ -0,0 +1,11 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require "rspec"
4
+ require "yaml"
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ourkudos
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.2
6
+ platform: ruby
7
+ authors:
8
+ - Marcin Walczak
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-05-05 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: nestful
17
+ requirement: &id001 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: rspec
28
+ requirement: &id002 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 2.3.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: bundler
39
+ requirement: &id003 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ version: 1.0.0
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *id003
48
+ - !ruby/object:Gem::Dependency
49
+ name: jeweler
50
+ requirement: &id004 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *id004
59
+ - !ruby/object:Gem::Dependency
60
+ name: rcov
61
+ requirement: &id005 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: *id005
70
+ description: OurKudos client api gem
71
+ email: marcin.walczak@gmail.com
72
+ executables: []
73
+
74
+ extensions: []
75
+
76
+ extra_rdoc_files:
77
+ - LICENSE.txt
78
+ - README.rdoc
79
+ files:
80
+ - .document
81
+ - Gemfile
82
+ - Gemfile.lock
83
+ - LICENSE.txt
84
+ - README.rdoc
85
+ - Rakefile
86
+ - VERSION
87
+ - lib/ourkudos.rb
88
+ - lib/ourkudos/config/config.yaml
89
+ - lib/ourkudos/our_kudos.rb
90
+ - lib/ourkudos/resource_editor.rb
91
+ - lib/ourkudos/response_codes.rb
92
+ - ourkudos.gemspec
93
+ - spec/our_kudos_spec.rb
94
+ - spec/spec_helper.rb
95
+ homepage: http://ourkudos.com
96
+ licenses:
97
+ - MIT
98
+ post_install_message:
99
+ rdoc_options: []
100
+
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ hash: 2113073079641666868
109
+ segments:
110
+ - 0
111
+ version: "0"
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: "0"
118
+ requirements: []
119
+
120
+ rubyforge_project:
121
+ rubygems_version: 1.8.0
122
+ signing_key:
123
+ specification_version: 3
124
+ summary: OurKudos client api gem
125
+ test_files: []
126
+