ledsign-api 0.1.0
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 +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +54 -0
- data/VERSION +1 -0
- data/ledsign-api.gemspec +57 -0
- data/lib/ledsign-api.rb +74 -0
- data/test/helper.rb +10 -0
- data/test/test_ledsign-api.rb +7 -0
- metadata +99 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2009 Christocracy
|
|
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,17 @@
|
|
|
1
|
+
= ledsign-api
|
|
2
|
+
|
|
3
|
+
This is an ActiveResource API for interacting with that LedSign[http://internetledsign]
|
|
4
|
+
|
|
5
|
+
== Note on Patches/Pull Requests
|
|
6
|
+
|
|
7
|
+
* Fork the project.
|
|
8
|
+
* Make your feature addition or bug fix.
|
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
|
10
|
+
future version unintentionally.
|
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
|
14
|
+
|
|
15
|
+
== Copyright
|
|
16
|
+
|
|
17
|
+
Copyright (c) 2010 Christocracy. See LICENSE for details.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'rake'
|
|
3
|
+
|
|
4
|
+
begin
|
|
5
|
+
require 'jeweler'
|
|
6
|
+
Jeweler::Tasks.new do |gem|
|
|
7
|
+
gem.name = "ledsign-api"
|
|
8
|
+
gem.summary = %Q{ActiveResource API for that LedSign}
|
|
9
|
+
gem.description = %Q{ActiveResource API Gem to interface with that LedSign}
|
|
10
|
+
gem.email = "christocracy@gmail.com"
|
|
11
|
+
gem.homepage = "http://github.com/christocracy/ledsign-api"
|
|
12
|
+
gem.authors = ["Christocracy"]
|
|
13
|
+
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
|
14
|
+
gem.add_dependency "activeresource", ">= 3.0.0.beta"
|
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
|
16
|
+
end
|
|
17
|
+
Jeweler::GemcutterTasks.new
|
|
18
|
+
rescue LoadError
|
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
require 'rake/testtask'
|
|
23
|
+
Rake::TestTask.new(:test) do |test|
|
|
24
|
+
test.libs << 'lib' << 'test'
|
|
25
|
+
test.pattern = 'test/**/test_*.rb'
|
|
26
|
+
test.verbose = true
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
begin
|
|
30
|
+
require 'rcov/rcovtask'
|
|
31
|
+
Rcov::RcovTask.new do |test|
|
|
32
|
+
test.libs << 'test'
|
|
33
|
+
test.pattern = 'test/**/test_*.rb'
|
|
34
|
+
test.verbose = true
|
|
35
|
+
end
|
|
36
|
+
rescue LoadError
|
|
37
|
+
task :rcov do
|
|
38
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
task :test => :check_dependencies
|
|
43
|
+
|
|
44
|
+
task :default => :test
|
|
45
|
+
|
|
46
|
+
require 'rake/rdoctask'
|
|
47
|
+
Rake::RDocTask.new do |rdoc|
|
|
48
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
|
49
|
+
|
|
50
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
51
|
+
rdoc.title = "ledsign-api #{version}"
|
|
52
|
+
rdoc.rdoc_files.include('README*')
|
|
53
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
54
|
+
end
|
data/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.1.0
|
data/ledsign-api.gemspec
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Generated by jeweler
|
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
|
4
|
+
# -*- encoding: utf-8 -*-
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |s|
|
|
7
|
+
s.name = %q{ledsign-api}
|
|
8
|
+
s.version = "0.1.0"
|
|
9
|
+
|
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
|
+
s.authors = ["Christocracy"]
|
|
12
|
+
s.date = %q{2010-04-01}
|
|
13
|
+
s.description = %q{ActiveResource API Gem to interface with that LedSign}
|
|
14
|
+
s.email = %q{christocracy@gmail.com}
|
|
15
|
+
s.extra_rdoc_files = [
|
|
16
|
+
"LICENSE",
|
|
17
|
+
"README.rdoc"
|
|
18
|
+
]
|
|
19
|
+
s.files = [
|
|
20
|
+
".document",
|
|
21
|
+
".gitignore",
|
|
22
|
+
"LICENSE",
|
|
23
|
+
"README.rdoc",
|
|
24
|
+
"Rakefile",
|
|
25
|
+
"VERSION",
|
|
26
|
+
"ledsign-api.gemspec",
|
|
27
|
+
"lib/ledsign-api.rb",
|
|
28
|
+
"test/helper.rb",
|
|
29
|
+
"test/test_ledsign-api.rb"
|
|
30
|
+
]
|
|
31
|
+
s.homepage = %q{http://github.com/christocracy/ledsign-api}
|
|
32
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
|
33
|
+
s.require_paths = ["lib"]
|
|
34
|
+
s.rubygems_version = %q{1.3.6}
|
|
35
|
+
s.summary = %q{ActiveResource API for that LedSign}
|
|
36
|
+
s.test_files = [
|
|
37
|
+
"test/helper.rb",
|
|
38
|
+
"test/test_ledsign-api.rb"
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
if s.respond_to? :specification_version then
|
|
42
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
43
|
+
s.specification_version = 3
|
|
44
|
+
|
|
45
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
|
46
|
+
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
|
47
|
+
s.add_runtime_dependency(%q<activeresource>, [">= 3.0.0.beta"])
|
|
48
|
+
else
|
|
49
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
|
50
|
+
s.add_dependency(%q<activeresource>, [">= 3.0.0.beta"])
|
|
51
|
+
end
|
|
52
|
+
else
|
|
53
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
|
54
|
+
s.add_dependency(%q<activeresource>, [">= 3.0.0.beta"])
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
data/lib/ledsign-api.rb
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
require "rubygems"
|
|
2
|
+
require "active_resource"
|
|
3
|
+
|
|
4
|
+
module LedSign
|
|
5
|
+
|
|
6
|
+
class Base < ActiveResource::Base
|
|
7
|
+
self.site = "http://internetledsign.com/api"
|
|
8
|
+
self.format = :json
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
class Msg < Base
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
class User < Base
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
class Log < Base
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
class Session
|
|
21
|
+
cattr_accessor :url
|
|
22
|
+
cattr_accessor :api_key
|
|
23
|
+
cattr_accessor :secret
|
|
24
|
+
cattr_accessor :protocol
|
|
25
|
+
self.protocol = 'https'
|
|
26
|
+
|
|
27
|
+
attr_accessor :token, :name
|
|
28
|
+
|
|
29
|
+
def self.setup(params)
|
|
30
|
+
params.each { |k,value| send("#{k}=", value) }
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def initialize(token = nil, params = nil)
|
|
34
|
+
self.token = token
|
|
35
|
+
|
|
36
|
+
if params && params[:signature]
|
|
37
|
+
unless self.class.validate_signature(params) && params[:timestamp].to_i > 24.hours.ago.utc.to_i
|
|
38
|
+
raise "Invalid Signature: Possible malicious login"
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def login_url
|
|
44
|
+
"http://#{self.class.url}/login/?api_key=#{api_key}"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Used by ActiveResource::Base to make all non-authentication API calls
|
|
48
|
+
# (ShopifyAPI::Base.site set in ShopifyLoginProtection#shopify_session)
|
|
49
|
+
def site
|
|
50
|
+
"#{protocol}://#{api_key}:#{computed_password}@#{self.class.url}"
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def valid?
|
|
54
|
+
token.present?
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
private
|
|
58
|
+
|
|
59
|
+
# The secret is computed by taking the shared_secret which we got when
|
|
60
|
+
# registring this third party application and concating the request_to it,
|
|
61
|
+
# and then calculating a MD5 hexdigest.
|
|
62
|
+
def computed_password
|
|
63
|
+
Digest::MD5.hexdigest(secret + token.to_s)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def self.validate_signature(params)
|
|
68
|
+
return false unless signature = params[:signature]
|
|
69
|
+
|
|
70
|
+
sorted_params = params.except(:signature, :action, :controller).collect{|k,v|"#{k}=#{v}"}.sort.join
|
|
71
|
+
Digest::MD5.hexdigest(secret + sorted_params) == signature
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
data/test/helper.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: ledsign-api
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
prerelease: false
|
|
5
|
+
segments:
|
|
6
|
+
- 0
|
|
7
|
+
- 1
|
|
8
|
+
- 0
|
|
9
|
+
version: 0.1.0
|
|
10
|
+
platform: ruby
|
|
11
|
+
authors:
|
|
12
|
+
- Christocracy
|
|
13
|
+
autorequire:
|
|
14
|
+
bindir: bin
|
|
15
|
+
cert_chain: []
|
|
16
|
+
|
|
17
|
+
date: 2010-04-01 00:00:00 -04:00
|
|
18
|
+
default_executable:
|
|
19
|
+
dependencies:
|
|
20
|
+
- !ruby/object:Gem::Dependency
|
|
21
|
+
name: thoughtbot-shoulda
|
|
22
|
+
prerelease: false
|
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
|
24
|
+
requirements:
|
|
25
|
+
- - ">="
|
|
26
|
+
- !ruby/object:Gem::Version
|
|
27
|
+
segments:
|
|
28
|
+
- 0
|
|
29
|
+
version: "0"
|
|
30
|
+
type: :development
|
|
31
|
+
version_requirements: *id001
|
|
32
|
+
- !ruby/object:Gem::Dependency
|
|
33
|
+
name: activeresource
|
|
34
|
+
prerelease: false
|
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
segments:
|
|
40
|
+
- 3
|
|
41
|
+
- 0
|
|
42
|
+
- 0
|
|
43
|
+
- beta
|
|
44
|
+
version: 3.0.0.beta
|
|
45
|
+
type: :runtime
|
|
46
|
+
version_requirements: *id002
|
|
47
|
+
description: ActiveResource API Gem to interface with that LedSign
|
|
48
|
+
email: christocracy@gmail.com
|
|
49
|
+
executables: []
|
|
50
|
+
|
|
51
|
+
extensions: []
|
|
52
|
+
|
|
53
|
+
extra_rdoc_files:
|
|
54
|
+
- LICENSE
|
|
55
|
+
- README.rdoc
|
|
56
|
+
files:
|
|
57
|
+
- .document
|
|
58
|
+
- .gitignore
|
|
59
|
+
- LICENSE
|
|
60
|
+
- README.rdoc
|
|
61
|
+
- Rakefile
|
|
62
|
+
- VERSION
|
|
63
|
+
- ledsign-api.gemspec
|
|
64
|
+
- lib/ledsign-api.rb
|
|
65
|
+
- test/helper.rb
|
|
66
|
+
- test/test_ledsign-api.rb
|
|
67
|
+
has_rdoc: true
|
|
68
|
+
homepage: http://github.com/christocracy/ledsign-api
|
|
69
|
+
licenses: []
|
|
70
|
+
|
|
71
|
+
post_install_message:
|
|
72
|
+
rdoc_options:
|
|
73
|
+
- --charset=UTF-8
|
|
74
|
+
require_paths:
|
|
75
|
+
- lib
|
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
77
|
+
requirements:
|
|
78
|
+
- - ">="
|
|
79
|
+
- !ruby/object:Gem::Version
|
|
80
|
+
segments:
|
|
81
|
+
- 0
|
|
82
|
+
version: "0"
|
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
|
+
requirements:
|
|
85
|
+
- - ">="
|
|
86
|
+
- !ruby/object:Gem::Version
|
|
87
|
+
segments:
|
|
88
|
+
- 0
|
|
89
|
+
version: "0"
|
|
90
|
+
requirements: []
|
|
91
|
+
|
|
92
|
+
rubyforge_project:
|
|
93
|
+
rubygems_version: 1.3.6
|
|
94
|
+
signing_key:
|
|
95
|
+
specification_version: 3
|
|
96
|
+
summary: ActiveResource API for that LedSign
|
|
97
|
+
test_files:
|
|
98
|
+
- test/helper.rb
|
|
99
|
+
- test/test_ledsign-api.rb
|