tagstand 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,55 @@
1
+ # rcov generated
2
+ coverage
3
+
4
+ # rdoc generated
5
+ rdoc
6
+
7
+ # yard generated
8
+ doc
9
+ .yardoc
10
+
11
+ # bundler
12
+ .bundle
13
+
14
+ # jeweler generated
15
+ pkg
16
+
17
+ # RVM generated
18
+ .rvmrc
19
+
20
+ *.gem
21
+ Gemfile.lock
22
+ .document
23
+
24
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
25
+ #
26
+ # * Create a file at ~/.gitignore
27
+ # * Include files you want ignored
28
+ # * Run: git config --global core.excludesfile ~/.gitignore
29
+ #
30
+ # After doing this, these files will be ignored in all your git projects,
31
+ # saving you from having to 'pollute' every project you touch with them
32
+ #
33
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
34
+ #
35
+ # For MacOS:
36
+ #
37
+ .DS_Store
38
+
39
+ # For TextMate
40
+ *.tmproj
41
+ tmtags
42
+
43
+ # For emacs:
44
+ #*~
45
+ #\#*
46
+ #.\#*
47
+
48
+ # For vim:
49
+ #*.swp
50
+
51
+ # For redcar:
52
+ #.redcar
53
+
54
+ # For rubinius:
55
+ #*.rbc
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'hashie'
4
+ gem 'httparty'
5
+ gem 'json'
6
+
7
+ group :development, :test do
8
+ gem 'fakeweb', '>= 1.3.0'
9
+ gem 'rspec', '>= 2.9.0'
10
+ end
@@ -0,0 +1,56 @@
1
+ = Tagstand
2
+
3
+ This gem is still under development. Use at your own risk.
4
+
5
+ == Requirements
6
+
7
+ You will need a {Tagstand API Key}[https://www.tagstand.com/signup] in order to get started.
8
+
9
+ == Installation
10
+
11
+ (sudo) gem install tagstand
12
+
13
+ == Usage
14
+
15
+ Please refer to the {Tagstand API Documentation}[https://manage.tagstand.com/api/docs] for more information about the API, or follow the examples below:
16
+
17
+ require 'tagstand'
18
+
19
+ Tagstand.api_key = ENV['TAGSTAND_API_KEY']
20
+
21
+ tags = Tagstand::Tag.create
22
+ tag.created_at
23
+ tag.votes
24
+
25
+ taps = Tagstand::Tap.list
26
+ taps.total_taps_count
27
+ taps.taps
28
+
29
+ user = Tagstand::User.create('sample@email.com')
30
+ key = Tagstand::User.key('sample@email.com', 'password')
31
+
32
+ And that's it!
33
+
34
+ == Errors
35
+
36
+ Errors are based on the HTTP response of the request, so that you can rescue accordingly:
37
+
38
+ rescue Tagstand::ClientError > req
39
+ rescue Tagstand::BadRequest > req
40
+ rescue Tagstand::NotFound > req
41
+ rescue Tagstand::Unauthorized > req
42
+
43
+ == Contributing to Tagstand
44
+
45
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
46
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
47
+ * Fork the project.
48
+ * Start a feature/bugfix branch.
49
+ * Commit and push until you are happy with your contribution.
50
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
51
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
52
+
53
+ == Copyright
54
+
55
+ Copyright (c) 2012 Tatemae Consultancy. See LICENSE.txt for further details.
56
+
@@ -0,0 +1,29 @@
1
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
2
+ require "bundler/version"
3
+ require "rake/testtask"
4
+ require "./lib/tagstand"
5
+ require 'rspec/core'
6
+ require 'rspec/core/rake_task'
7
+
8
+ RSpec::Core::RakeTask.new(:spec) do |spec|
9
+ spec.pattern = FileList['spec/**/*_spec.rb']
10
+ end
11
+
12
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
13
+ spec.pattern = 'spec/**/*_spec.rb'
14
+ spec.rcov = true
15
+ end
16
+
17
+ task :default => :spec
18
+
19
+ desc "Build the gem"
20
+ task :build do
21
+ system "gem build tagstand.gemspec"
22
+ end
23
+
24
+ desc "Build and release the gem"
25
+ task :release => :build do
26
+ system "gem push tagstand-#{Tagstand::VERSION}.gem"
27
+ end
28
+
29
+ task :default => :test
@@ -0,0 +1,97 @@
1
+ require 'cgi'
2
+ require 'uri'
3
+ require 'httparty'
4
+ require 'hashie'
5
+ Hash.send :include, Hashie::HashExtensions
6
+
7
+ libdir = File.dirname(__FILE__)
8
+ $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
9
+
10
+ require 'tagstand/version'
11
+ require 'tagstand/tag'
12
+ require 'tagstand/tap'
13
+ require 'tagstand/user'
14
+
15
+ module Tagstand
16
+ class << self
17
+ # Allow Tagstand.api_key = "..."
18
+ def api_key=(api_key)
19
+ Tagstand.api_key = api_key
20
+ end
21
+
22
+ def base_uri=(uri)
23
+ Tagstand.base_uri uri
24
+ end
25
+
26
+ # Allows the initializer to turn off actually communicating to the REST service for certain environments
27
+ # Requires fakeweb gem to be installed
28
+ def disable
29
+ FakeWeb.register_uri(:any, %r|#{Regexp.escape(Tagstand.base_uri)}|, :body => '{"Disabled":true}', :content_type => 'application/json; charset=utf-8')
30
+ end
31
+ end
32
+
33
+ # Represents a Tagstand API error and contains specific data about the error.
34
+ class TagstandError < StandardError
35
+ attr_reader :data
36
+ def initialize(data)
37
+ @data = Hashie::Mash.new(data)
38
+ super "The Tagstand API responded with the following error - #{data}"
39
+ end
40
+ end
41
+
42
+ class ClientError < StandardError; end
43
+ class ServerError < StandardError; end
44
+ class BadRequest < TagstandError; end
45
+ class Unauthorized < StandardError; end
46
+ class NotFound < ClientError; end
47
+ class Unavailable < StandardError; end
48
+
49
+ class Tagstand
50
+ include HTTParty
51
+
52
+ @@base_uri = "https://manage.tagstand.com/api/"
53
+ @@api_key = ""
54
+ headers({
55
+ 'User-Agent' => "tagstand-gem-#{VERSION}",
56
+ 'Content-Type' => 'application/json; charset=utf-8',
57
+ 'Accept-Encoding' => 'gzip, deflate'
58
+ })
59
+ base_uri @@base_uri
60
+
61
+ class << self
62
+ # Get the API key
63
+ def api_key; @@api_key end
64
+
65
+ # Set the API key
66
+ def api_key=(api_key)
67
+ return @@api_key unless api_key
68
+ @@api_key = api_key
69
+ end
70
+
71
+ # Get the Base URI.
72
+ def base_uri; @@base_uri end
73
+
74
+ def get(*args); handle_response super end
75
+ def post(*args); handle_response super end
76
+ def put(*args); handle_response super end
77
+ def delete(*args); handle_response super end
78
+
79
+ def handle_response(response) # :nodoc:
80
+ case response.code
81
+ when 400
82
+ raise BadRequest.new response.parsed_response
83
+ when 401
84
+ raise Unauthorized.new
85
+ when 404
86
+ raise NotFound.new
87
+ when 400...500
88
+ raise ClientError.new response.parsed_response
89
+ when 500...600
90
+ raise ServerError.new
91
+ else
92
+ response
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,64 @@
1
+ require 'tagstand'
2
+ require 'json'
3
+
4
+ module Tagstand
5
+ # Represents a tag
6
+ class Tag
7
+ class << self
8
+
9
+ # TODO: document this method
10
+ # TODO: POST body causing error
11
+ def create(tag=nil)
12
+ options = {query: {api_key: Tagstand.api_key}}
13
+ options.merge!(body: "tag=#{tag.to_json}") if tag
14
+ response = Tagstand.post "/tag_create", options
15
+ Hashie::Mash.new(response)
16
+ end
17
+
18
+ # TODO: document this method
19
+ # id can be either a number (Int) or URL key (String)
20
+ def destroy(id)
21
+ query = {api_key: Tagstand.api_key}
22
+ ident = id.is_a?(Integer) ? {number: id} : {url_key: id}
23
+ query.merge!(ident)
24
+ options = {query: query}
25
+ response = Tagstand.get "/tag_destroy", options
26
+ Hashie::Mash.new(response)
27
+ end
28
+
29
+ # TODO: document this method
30
+ # Args: order, name_prefix_filter, data_type_filter, number_filter, page, num_per_page
31
+ def list(args={})
32
+ options = {query: {api_key: Tagstand.api_key}}
33
+ options.merge!(args) unless args.empty?
34
+ response = Tagstand.get "/tag_list", options
35
+ Hashie::Mash.new(response)
36
+ end
37
+
38
+ # TODO: document this method
39
+ # id can be either a number (Int) or URL key (String)
40
+ def show(id)
41
+ query = {api_key: Tagstand.api_key}
42
+ ident = id.is_a?(Integer) ? {number: id} : {url_key: id}
43
+ query.merge!(ident)
44
+ options = {query: query}
45
+ response = Tagstand.get "/tag_show", options
46
+ Hashie::Mash.new(response)
47
+ end
48
+
49
+ # TODO: document this method
50
+ # id can be either a number (Int) or URL key (String)
51
+ # TODO: POST body causing error
52
+ def update(id, tag=nil)
53
+ query = {api_key: Tagstand.api_key}
54
+ ident = id.is_a?(Integer) ? {number: id} : {url_key: id}
55
+ query.merge!(ident)
56
+ options = {query: query}
57
+ options.merge!(body: "tag=#{tag.to_json}") if tag
58
+ response = Tagstand.post "/tag_update", options
59
+ Hashie::Mash.new(response)
60
+ end
61
+
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,20 @@
1
+ require 'tagstand'
2
+ require 'json'
3
+
4
+ module Tagstand
5
+ # Represents a tap
6
+ class Tap
7
+ class << self
8
+
9
+ # TODO: document this method
10
+ # Args: order, tag_name_prefix_filter, tag_data_type_filter, tag_number_filter, page, num_per_page
11
+ def list(args={})
12
+ options = {query: {api_key: Tagstand.api_key}}
13
+ options.merge!(args) unless args.empty?
14
+ response = Tagstand.get "/tap_list", options
15
+ Hashie::Mash.new(response)
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,29 @@
1
+ require 'tagstand'
2
+ require 'json'
3
+
4
+ module Tagstand
5
+ # Represents a user
6
+ class User
7
+ class << self
8
+
9
+ # TODO: document this method
10
+ # TODO: POST body causing error
11
+ def create(email, pwd=nil)
12
+ options = {query: {api_key: Tagstand.api_key}}
13
+ user = {email: email}
14
+ user.merge!(password: pwd) if pwd
15
+ options.merge!(body: "user=#{user.to_json}")
16
+ response = Tagstand.post "/user_create", options
17
+ Hashie::Mash.new(response)
18
+ end
19
+
20
+ # TODO: document this method
21
+ def key(email, pwd)
22
+ options = {query: {api_key: Tagstand.api_key, email: email, password: pwd}}
23
+ response = Tagstand.get "/user_key", options
24
+ Hashie::Mash.new(response)
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ module Tagstand
2
+ VERSION = "0.0.1" unless defined?(Tagstand::VERSION)
3
+ end
@@ -0,0 +1 @@
1
+ require 'tagstand'
@@ -0,0 +1,11 @@
1
+ require 'fakeweb'
2
+ require 'tagstand'
3
+
4
+ FakeWeb.allow_net_connect = false
5
+
6
+ RSpec.configure do |config|
7
+ config.before(:each) do
8
+ FakeWeb.clean_registry
9
+ Tagstand.api_key = '123abc456def789ghi'
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+ {
2
+ "created_at":"2012-05-22T17:19:14Z",
3
+ "custom":true,
4
+ "data":"hi",
5
+ "data_type":"text",
6
+ "deleted":null,
7
+ "id":44258,
8
+ "name":"first",
9
+ "num_checkins":0,
10
+ "number":37,
11
+ "pass_uuid_param":null,
12
+ "sign_url":null,
13
+ "source":"api",
14
+ "updated_at":"2012-05-22T17:19:14Z",
15
+ "url_key":"vbd4du",
16
+ "user_id":4,
17
+ "votes":0
18
+ }
@@ -0,0 +1,27 @@
1
+ require 'bundler'
2
+ require 'bundler/version'
3
+
4
+ require File.expand_path('lib/tagstand/version')
5
+
6
+ Gem::Specification.new do |s|
7
+ s.add_runtime_dependency('hashie')
8
+ s.add_runtime_dependency('httparty')
9
+ s.add_runtime_dependency('json')
10
+ s.add_development_dependency('fakeweb')
11
+ s.add_development_dependency('rspec')
12
+ s.name = "tagstand"
13
+ s.authors = ["Brian Getting"]
14
+ s.description = %q{Implements the complete functionality of the Tagstand Tag Manager API beta (v0.2).}
15
+ s.email = ["brian@tatem.ae"]
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
17
+ s.extra_rdoc_files = ["README.rdoc"]
18
+ s.files = `git ls-files`.split("\n")
19
+ s.homepage = "http://github.com/tatemae-consultancy/tagstand"
20
+ s.licenses = ["MIT"]
21
+ s.require_paths = ["lib"]
22
+ s.summary = %q{A library which implements the complete functionality of the Tagstand Tag Manager API beta (v0.2).}
23
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
24
+ s.version = Tagstand::VERSION
25
+ s.platform = Gem::Platform::RUBY
26
+ s.required_rubygems_version = Gem::Requirement.new('>= 1.3.6') if s.respond_to? :required_rubygems_version=
27
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tagstand
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Brian Getting
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: hashie
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: httparty
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: json
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: fakeweb
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
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'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: Implements the complete functionality of the Tagstand Tag Manager API
95
+ beta (v0.2).
96
+ email:
97
+ - brian@tatem.ae
98
+ executables: []
99
+ extensions: []
100
+ extra_rdoc_files:
101
+ - README.rdoc
102
+ files:
103
+ - .gitignore
104
+ - Gemfile
105
+ - README.rdoc
106
+ - Rakefile
107
+ - lib/tagstand.rb
108
+ - lib/tagstand/tag.rb
109
+ - lib/tagstand/tap.rb
110
+ - lib/tagstand/user.rb
111
+ - lib/tagstand/version.rb
112
+ - rails/init.rb
113
+ - spec/spec_helper.rb
114
+ - spec/tagstand/fixtures/tag.json
115
+ - tagstand.gemspec
116
+ homepage: http://github.com/tatemae-consultancy/tagstand
117
+ licenses:
118
+ - MIT
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ none: false
125
+ requirements:
126
+ - - ! '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ! '>='
133
+ - !ruby/object:Gem::Version
134
+ version: 1.3.6
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 1.8.24
138
+ signing_key:
139
+ specification_version: 3
140
+ summary: A library which implements the complete functionality of the Tagstand Tag
141
+ Manager API beta (v0.2).
142
+ test_files:
143
+ - spec/spec_helper.rb
144
+ - spec/tagstand/fixtures/tag.json