loopiator 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +9 -0
- data/README.md +4 -0
- data/Rakefile +87 -0
- data/lib/generators/loopiator/loopiator_generator.rb +18 -0
- data/lib/generators/templates/loopia.template.yml +16 -0
- data/lib/loopiator/client.rb +79 -0
- data/lib/loopiator/credits.rb +15 -0
- data/lib/loopiator/domains.rb +47 -0
- data/lib/loopiator/errors.rb +33 -0
- data/lib/loopiator/extensions/hash.rb +9 -0
- data/lib/loopiator/logger.rb +9 -0
- data/lib/loopiator/models/domain.rb +34 -0
- data/lib/loopiator/railtie.rb +12 -0
- data/lib/loopiator.rb +20 -0
- data/loopiator.gemspec +45 -0
- data/spec/loopiator/client_spec.rb +33 -0
- data/spec/loopiator/credits_spec.rb +28 -0
- data/spec/loopiator/domains_spec.rb +75 -0
- data/spec/spec_helper.rb +26 -0
- metadata +131 -0
data/Gemfile
ADDED
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
## helper functions
|
2
|
+
|
3
|
+
def name
|
4
|
+
@name ||= Dir['*.gemspec'].first.split('.').first
|
5
|
+
end
|
6
|
+
|
7
|
+
def version
|
8
|
+
line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
|
9
|
+
line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
|
10
|
+
end
|
11
|
+
|
12
|
+
def gemspec_file
|
13
|
+
"#{name}.gemspec"
|
14
|
+
end
|
15
|
+
|
16
|
+
def gem_file
|
17
|
+
"#{name}-#{version}.gem"
|
18
|
+
end
|
19
|
+
|
20
|
+
def replace_header(head, header_name)
|
21
|
+
head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
|
22
|
+
end
|
23
|
+
|
24
|
+
begin
|
25
|
+
# Rspec 2.0
|
26
|
+
require 'rspec/core/rake_task'
|
27
|
+
|
28
|
+
desc 'Default: run specs'
|
29
|
+
task :default => :spec
|
30
|
+
RSpec::Core::RakeTask.new do |t|
|
31
|
+
t.pattern = "spec/**/*_spec.rb"
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new('rcov') do |t|
|
35
|
+
t.pattern = "spec/**/*_spec.rb"
|
36
|
+
t.rcov = true
|
37
|
+
t.rcov_opts = ['--exclude', 'spec']
|
38
|
+
end
|
39
|
+
|
40
|
+
rescue LoadError
|
41
|
+
puts "Rspec not available. Install it with: gem install rspec"
|
42
|
+
end
|
43
|
+
|
44
|
+
## release management tasks
|
45
|
+
|
46
|
+
desc "Commit, create tag v#{version} and build and push #{gem_file} to Rubygems"
|
47
|
+
task :release => :build do
|
48
|
+
sh "git commit --allow-empty -a -m 'Release #{version}'"
|
49
|
+
sh "git tag v#{version}"
|
50
|
+
sh "git push"
|
51
|
+
sh "git push origin v#{version}"
|
52
|
+
sh "gem push pkg/#{gem_file}"
|
53
|
+
end
|
54
|
+
|
55
|
+
desc "Build #{gem_file} into the pkg directory"
|
56
|
+
task :build => :gemspec do
|
57
|
+
sh "mkdir -p pkg"
|
58
|
+
sh "gem build #{gemspec_file}"
|
59
|
+
sh "mv #{gem_file} pkg"
|
60
|
+
end
|
61
|
+
|
62
|
+
desc "Generate #{gemspec_file}"
|
63
|
+
task :gemspec do
|
64
|
+
# read spec file and split out manifest section
|
65
|
+
spec = File.read(gemspec_file)
|
66
|
+
head, manifest, tail = spec.split(" # = MANIFEST =\n")
|
67
|
+
|
68
|
+
# replace name version and date
|
69
|
+
replace_header(head, :name)
|
70
|
+
replace_header(head, :version)
|
71
|
+
|
72
|
+
# determine file list from git ls-files
|
73
|
+
files = `git ls-files`.
|
74
|
+
split("\n").
|
75
|
+
sort.
|
76
|
+
reject { |file| file =~ /^\./ }.
|
77
|
+
reject { |file| file =~ /^(rdoc|pkg)/ }.
|
78
|
+
map { |file| " #{file}" }.
|
79
|
+
join("\n")
|
80
|
+
|
81
|
+
# piece file back together and write
|
82
|
+
manifest = " s.files = %w[\n#{files}\n ]\n"
|
83
|
+
spec = [head, manifest, tail].join(" # = MANIFEST =\n")
|
84
|
+
File.open(gemspec_file, 'w') { |io| io.write(spec) }
|
85
|
+
puts "Updated #{gemspec_file}"
|
86
|
+
end
|
87
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'generators/helpers/file_helper'
|
2
|
+
|
3
|
+
module Loopiator
|
4
|
+
module Generators
|
5
|
+
class LoopiatorGenerator < Rails::Generators::Base
|
6
|
+
namespace "loopiator"
|
7
|
+
source_root File.expand_path("../../templates", __FILE__)
|
8
|
+
|
9
|
+
desc "Copies loopia.yml to the Rails app's config directory."
|
10
|
+
|
11
|
+
def copy_config
|
12
|
+
template "loopia.template.yml", "config/loopia.yml"
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
---
|
2
|
+
development:
|
3
|
+
username: "your-username"
|
4
|
+
password: "your-password"
|
5
|
+
endpoint: "https://api.loopia.se/RPCSERV"
|
6
|
+
|
7
|
+
test:
|
8
|
+
username: "your-username"
|
9
|
+
password: "your-password"
|
10
|
+
endpoint: "https://api.loopia.se/RPCSERV"
|
11
|
+
|
12
|
+
production:
|
13
|
+
username: "your-username"
|
14
|
+
password: "your-password"
|
15
|
+
endpoint: "https://api.loopia.se/RPCSERV"
|
16
|
+
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'cgi'
|
3
|
+
require 'rubygems'
|
4
|
+
require 'xmlrpc/client'
|
5
|
+
require 'simpleidn'
|
6
|
+
|
7
|
+
module Loopiator
|
8
|
+
class Client
|
9
|
+
attr_accessor :config, :client, :username, :password, :endpoint
|
10
|
+
|
11
|
+
include Loopiator::Logger
|
12
|
+
|
13
|
+
def initialize(options = {})
|
14
|
+
@config = set_config
|
15
|
+
|
16
|
+
options.symbolize_keys!
|
17
|
+
@config.merge!(options)
|
18
|
+
|
19
|
+
@username = @config.fetch(:username, nil)
|
20
|
+
@password = @config.fetch(:password, nil)
|
21
|
+
@endpoint = @config.fetch(:endpoint, nil)
|
22
|
+
|
23
|
+
timeout = options.fetch(:timeout, 500)
|
24
|
+
|
25
|
+
set_client(timeout)
|
26
|
+
end
|
27
|
+
|
28
|
+
def set_config
|
29
|
+
rails_env = defined?(Rails) ? Rails.env : "development"
|
30
|
+
config ||= YAML.load_file(File.join(Rails.root, "config/loopia.yml"))[rails_env] if defined?(Rails)
|
31
|
+
config ||= YAML.load_file(File.join(File.dirname(__FILE__), "../generators/templates/loopia.yml"))[rails_env] rescue nil
|
32
|
+
config ||= YAML.load_file(File.join(File.dirname(__FILE__), "../generators/templates/loopia.template.yml"))[rails_env] rescue nil
|
33
|
+
config ||= {}
|
34
|
+
|
35
|
+
config.symbolize_keys!
|
36
|
+
|
37
|
+
return config
|
38
|
+
end
|
39
|
+
|
40
|
+
def set_client(timeout = 500)
|
41
|
+
@client = XMLRPC::Client.new_from_uri(@endpoint)
|
42
|
+
@client.instance_variable_get(:@http).instance_variable_set(:@verify_mode, OpenSSL::SSL::VERIFY_NONE)
|
43
|
+
@client.timeout = timeout
|
44
|
+
@client
|
45
|
+
end
|
46
|
+
|
47
|
+
def call(rpc_method, *args)
|
48
|
+
response = ""
|
49
|
+
|
50
|
+
begin
|
51
|
+
response = @client.call(rpc_method, @username, @password, *args)
|
52
|
+
|
53
|
+
rescue EOFError => eof_error
|
54
|
+
raise Loopiator::ConnectionError
|
55
|
+
end
|
56
|
+
|
57
|
+
return response
|
58
|
+
end
|
59
|
+
|
60
|
+
def parse_status_response(response)
|
61
|
+
response = response.downcase.to_sym
|
62
|
+
|
63
|
+
case response
|
64
|
+
when :ok then return response
|
65
|
+
when :domain_occupied then return response
|
66
|
+
when :auth_error then raise Loopiator::AuthError
|
67
|
+
when :rate_limited then raise Loopiator::RateLimitError
|
68
|
+
when :bad_indata then raise Loopiator::InvalidParameterError
|
69
|
+
when :unknown_error then raise Loopiator::UnknownError
|
70
|
+
else
|
71
|
+
return response
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
include Loopiator::Domains
|
76
|
+
include Loopiator::Credits
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Loopiator
|
2
|
+
module Credits
|
3
|
+
|
4
|
+
# https://www.loopia.se/api/getcreditsamount/
|
5
|
+
def get_credits_amount(with_vat = true, customer_number = "")
|
6
|
+
call("getCreditsAmount", customer_number, with_vat).to_f
|
7
|
+
end
|
8
|
+
|
9
|
+
# https://www.loopia.se/api/payinvoiceusingcredits/
|
10
|
+
def pay_invoice_using_credits(reference_number, customer_number = "")
|
11
|
+
parse_status_response(call("payInvoiceUsingCredits", customer_number, reference_number.to_s))
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Loopiator
|
2
|
+
module Domains
|
3
|
+
|
4
|
+
def domain_is_free(domain_name)
|
5
|
+
response = parse_status_response(call("domainIsFree", encode_domain(domain_name)))
|
6
|
+
|
7
|
+
return response.eql?(:ok)
|
8
|
+
end
|
9
|
+
|
10
|
+
def get_domain(domain_name, customer_number = "")
|
11
|
+
domain = nil
|
12
|
+
response = call("getDomain", customer_number, encode_domain(domain_name))
|
13
|
+
|
14
|
+
if (response && response.is_a?(Hash))
|
15
|
+
domain = Loopiator::Models::Domain.new(response)
|
16
|
+
end
|
17
|
+
|
18
|
+
return domain
|
19
|
+
end
|
20
|
+
|
21
|
+
def add_domain_to_account(domain_name, should_buy = false, customer_number = "")
|
22
|
+
response = parse_status_response(call("addDomainToAccount", customer_number, encode_domain(domain_name), should_buy))
|
23
|
+
|
24
|
+
return response.eql?(:ok)
|
25
|
+
end
|
26
|
+
|
27
|
+
def purchase_domain(domain_name, customer_number = "")
|
28
|
+
success = false
|
29
|
+
|
30
|
+
if (add_domain_to_account(domain_name, true, customer_number))
|
31
|
+
domain = get_domain(domain_name, customer_number)
|
32
|
+
|
33
|
+
if (domain && domain.needs_to_be_paid? && domain.reference_number != nil && domain.reference_number != "")
|
34
|
+
success = pay_invoice_using_credits(domain.reference_number, customer_number)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
return success
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
def encode_domain(domain_name)
|
43
|
+
SimpleIDN.to_ascii(domain_name)
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Loopiator
|
2
|
+
class ApiError < StandardError; end
|
3
|
+
|
4
|
+
class AuthError < ApiError
|
5
|
+
def message
|
6
|
+
"You've supplied invalid authentication credentials. Please check your credentials and then try again."
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class RateLimitError < ApiError
|
11
|
+
def message
|
12
|
+
"You've reached the number of allowed API-requests within the given time period. Please wait a bit and then try again."
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class InvalidParameterError < ApiError
|
17
|
+
def message
|
18
|
+
"One or several parameters have invalid parameters supplied."
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class UnknownError < ApiError
|
23
|
+
def message
|
24
|
+
"An unknown error occurred while trying to request data from the API."
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class ConnectionError < ApiError
|
29
|
+
def message
|
30
|
+
"An unknown connection error occurred while trying to connect to the API."
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Loopiator
|
2
|
+
module Models
|
3
|
+
|
4
|
+
class Domain
|
5
|
+
attr_accessor :paid, :unpaid_amount, :registered, :domain, :renewal_status, :expiration_date, :reference_number
|
6
|
+
|
7
|
+
def initialize(hash)
|
8
|
+
hash.symbolize_keys!
|
9
|
+
|
10
|
+
self.paid = hash.fetch(:paid, 0).eql?(1)
|
11
|
+
self.unpaid_amount = hash.fetch(:unpaid_amount, 0)
|
12
|
+
self.registered = hash.fetch(:registered, 0).eql?(1)
|
13
|
+
self.domain = hash.fetch(:domain, "")
|
14
|
+
self.renewal_status = hash.fetch(:renewal_status, "")
|
15
|
+
self.expiration_date = hash.fetch(:expiration_date, "")
|
16
|
+
self.reference_number = hash.fetch(:reference_no, "").to_s
|
17
|
+
end
|
18
|
+
|
19
|
+
def paid?
|
20
|
+
paid
|
21
|
+
end
|
22
|
+
|
23
|
+
def registered?
|
24
|
+
registered
|
25
|
+
end
|
26
|
+
|
27
|
+
def needs_to_be_paid?
|
28
|
+
(!paid? && unpaid_amount > 0)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
data/lib/loopiator.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module Loopiator
|
2
|
+
VERSION = "0.1.0"
|
3
|
+
|
4
|
+
require File.join(File.dirname(__FILE__), 'loopiator/railtie') if defined?(Rails)
|
5
|
+
|
6
|
+
if (!Hash.instance_methods(false).include?(:symbolize_keys!))
|
7
|
+
require File.join(File.dirname(__FILE__), 'loopiator/extensions/hash')
|
8
|
+
end
|
9
|
+
|
10
|
+
require File.join(File.dirname(__FILE__), 'loopiator/logger')
|
11
|
+
require File.join(File.dirname(__FILE__), 'loopiator/errors')
|
12
|
+
|
13
|
+
require File.join(File.dirname(__FILE__), 'loopiator/models/domain')
|
14
|
+
|
15
|
+
require File.join(File.dirname(__FILE__), 'loopiator/domains')
|
16
|
+
require File.join(File.dirname(__FILE__), 'loopiator/credits')
|
17
|
+
|
18
|
+
require File.join(File.dirname(__FILE__), 'loopiator/client')
|
19
|
+
end
|
20
|
+
|
data/loopiator.gemspec
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.specification_version = 2 if s.respond_to? :specification_version=
|
3
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.3.5") if s.respond_to? :required_rubygems_version=
|
4
|
+
|
5
|
+
s.name = 'loopiator'
|
6
|
+
s.version = '0.1.0'
|
7
|
+
|
8
|
+
s.homepage = "https://github.com/Agiley/Loopiator"
|
9
|
+
s.email = "sebastian@agiley.se"
|
10
|
+
s.authors = ["Sebastian Johnsson"]
|
11
|
+
s.description = "Interface for communicating with Loopia's API"
|
12
|
+
s.summary = "Interface for communicating with Loopia's API"
|
13
|
+
|
14
|
+
s.add_dependency 'simpleidn', '>= 0.0.4'
|
15
|
+
|
16
|
+
s.add_development_dependency 'rake'
|
17
|
+
s.add_development_dependency 'rspec'
|
18
|
+
s.add_development_dependency 'mocha'
|
19
|
+
|
20
|
+
# = MANIFEST =
|
21
|
+
s.files = %w[
|
22
|
+
Gemfile
|
23
|
+
README.md
|
24
|
+
Rakefile
|
25
|
+
lib/generators/loopiator/loopiator_generator.rb
|
26
|
+
lib/generators/templates/loopia.template.yml
|
27
|
+
lib/loopiator.rb
|
28
|
+
lib/loopiator/client.rb
|
29
|
+
lib/loopiator/credits.rb
|
30
|
+
lib/loopiator/domains.rb
|
31
|
+
lib/loopiator/errors.rb
|
32
|
+
lib/loopiator/extensions/hash.rb
|
33
|
+
lib/loopiator/logger.rb
|
34
|
+
lib/loopiator/models/domain.rb
|
35
|
+
lib/loopiator/railtie.rb
|
36
|
+
loopiator.gemspec
|
37
|
+
spec/loopiator/client_spec.rb
|
38
|
+
spec/loopiator/credits_spec.rb
|
39
|
+
spec/loopiator/domains_spec.rb
|
40
|
+
spec/spec_helper.rb
|
41
|
+
]
|
42
|
+
# = MANIFEST =
|
43
|
+
|
44
|
+
s.test_files = s.files.select { |path| path =~ %r{^spec/*/.+\.rb} }
|
45
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Loopiator Api Client" do
|
4
|
+
describe "- When initializing a new client" do
|
5
|
+
|
6
|
+
describe "- With defaults:" do
|
7
|
+
before(:each) do
|
8
|
+
config = {username: "test_user",
|
9
|
+
password: "test_password",
|
10
|
+
endpoint: "https://api.loopia.se/RPCSERV" }
|
11
|
+
|
12
|
+
Loopiator::Client.any_instance.expects(:set_config).at_least_once.returns(config)
|
13
|
+
|
14
|
+
@client = Loopiator::Client.new(config)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should have a username set" do
|
18
|
+
@client.username.should == "test_user"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should have a password set" do
|
22
|
+
@client.password.should == "test_password"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should have an endpoint set" do
|
26
|
+
@client.endpoint.should == "https://api.loopia.se/RPCSERV"
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
4
|
+
|
5
|
+
describe "Credits Management -" do
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@client = Loopiator::Client.new
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "When managing my credits:" do
|
12
|
+
|
13
|
+
it "I should be able to check how many credits I currently have (with VAT)" do
|
14
|
+
@client.expects(:get_credits_amount).with(true).once.returns(125)
|
15
|
+
remaining_credits = @client.get_credits_amount(true)
|
16
|
+
remaining_credits.should == 125
|
17
|
+
end
|
18
|
+
|
19
|
+
it "I should be able to check how many credits I currently have (without VAT)" do
|
20
|
+
@client.expects(:get_credits_amount).with(false).once.returns(100)
|
21
|
+
remaining_credits = @client.get_credits_amount(false)
|
22
|
+
remaining_credits.should == 100
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
4
|
+
|
5
|
+
describe "Domain Management -" do
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@client = Loopiator::Client.new
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "When checking domain availability:" do
|
12
|
+
|
13
|
+
it "I should be able to check that a domain is available" do
|
14
|
+
@client.domain_is_free('dsadsadsadsadsadsadasdas.se').should == true
|
15
|
+
end
|
16
|
+
|
17
|
+
it "I should be able to check if a domain is not available" do
|
18
|
+
@client.domain_is_free('aftonbladet.se').should == false
|
19
|
+
end
|
20
|
+
|
21
|
+
it "I should be able to check if an IDN-domain is available" do
|
22
|
+
@client.domain_is_free('såhärtestarmanenidndomänkanske.se').should == true
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "When managing my domains:" do
|
28
|
+
|
29
|
+
it "I should be able to check the details for a domain that I own" do
|
30
|
+
hash = {"paid" => 1,
|
31
|
+
"unpaid_amount" => 0,
|
32
|
+
"registered" => 1,
|
33
|
+
"domain" => "testdomain.se",
|
34
|
+
"renewal_status" => "NOT_HANDLED_BY_LOOPIA",
|
35
|
+
"expiration_date" => "UNKNOWN",
|
36
|
+
"reference_no" => "999999"
|
37
|
+
}
|
38
|
+
|
39
|
+
mock = Loopiator::Models::Domain.new(hash)
|
40
|
+
|
41
|
+
@client.expects(:get_domain).with('testdomain.se').once.returns(mock)
|
42
|
+
|
43
|
+
domain = @client.get_domain('testdomain.se')
|
44
|
+
|
45
|
+
domain.paid?.should == true
|
46
|
+
domain.needs_to_be_paid?.should == false
|
47
|
+
domain.registered?.should == true
|
48
|
+
domain.reference_number.should == "999999"
|
49
|
+
end
|
50
|
+
|
51
|
+
it "I should be able to see that a domain hasn't been paid for yet." do
|
52
|
+
hash = {"paid" => 0,
|
53
|
+
"unpaid_amount" => 99,
|
54
|
+
"registered" => 1,
|
55
|
+
"domain" => "testdomain.se",
|
56
|
+
"renewal_status" => "NOT_HANDLED_BY_LOOPIA",
|
57
|
+
"expiration_date" => "UNKNOWN",
|
58
|
+
"reference_no" => "1111111"
|
59
|
+
}
|
60
|
+
|
61
|
+
mock = Loopiator::Models::Domain.new(hash)
|
62
|
+
|
63
|
+
@client.expects(:get_domain).with('testdomain.se').once.returns(mock)
|
64
|
+
|
65
|
+
domain = @client.get_domain('testdomain.se')
|
66
|
+
|
67
|
+
domain.paid?.should == false
|
68
|
+
domain.needs_to_be_paid?.should == true
|
69
|
+
domain.unpaid_amount.should == 99
|
70
|
+
domain.reference_number.should == "1111111"
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
$LOAD_PATH << "." unless $LOAD_PATH.include?(".")
|
2
|
+
|
3
|
+
begin
|
4
|
+
require "rubygems"
|
5
|
+
require "bundler"
|
6
|
+
|
7
|
+
if Gem::Version.new(Bundler::VERSION) <= Gem::Version.new("0.9.5")
|
8
|
+
raise RuntimeError, "Your bundler version is too old." +
|
9
|
+
"Run `gem install bundler` to upgrade."
|
10
|
+
end
|
11
|
+
|
12
|
+
# Set up load paths for all bundled gems
|
13
|
+
Bundler.setup
|
14
|
+
rescue Bundler::GemNotFound
|
15
|
+
raise RuntimeError, "Bundler couldn't find some gems." +
|
16
|
+
"Did you run \`bundlee install\`?"
|
17
|
+
end
|
18
|
+
|
19
|
+
#require "active_record"
|
20
|
+
Bundler.require
|
21
|
+
|
22
|
+
require File.expand_path('../../lib/loopiator', __FILE__)
|
23
|
+
|
24
|
+
RSpec.configure do |config|
|
25
|
+
config.mock_with :mocha
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: loopiator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Sebastian Johnsson
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-26 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: simpleidn
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.0.4
|
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.0.4
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
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: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
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: mocha
|
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
|
+
description: Interface for communicating with Loopia's API
|
79
|
+
email: sebastian@agiley.se
|
80
|
+
executables: []
|
81
|
+
extensions: []
|
82
|
+
extra_rdoc_files: []
|
83
|
+
files:
|
84
|
+
- Gemfile
|
85
|
+
- README.md
|
86
|
+
- Rakefile
|
87
|
+
- lib/generators/loopiator/loopiator_generator.rb
|
88
|
+
- lib/generators/templates/loopia.template.yml
|
89
|
+
- lib/loopiator.rb
|
90
|
+
- lib/loopiator/client.rb
|
91
|
+
- lib/loopiator/credits.rb
|
92
|
+
- lib/loopiator/domains.rb
|
93
|
+
- lib/loopiator/errors.rb
|
94
|
+
- lib/loopiator/extensions/hash.rb
|
95
|
+
- lib/loopiator/logger.rb
|
96
|
+
- lib/loopiator/models/domain.rb
|
97
|
+
- lib/loopiator/railtie.rb
|
98
|
+
- loopiator.gemspec
|
99
|
+
- spec/loopiator/client_spec.rb
|
100
|
+
- spec/loopiator/credits_spec.rb
|
101
|
+
- spec/loopiator/domains_spec.rb
|
102
|
+
- spec/spec_helper.rb
|
103
|
+
homepage: https://github.com/Agiley/Loopiator
|
104
|
+
licenses: []
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
none: false
|
111
|
+
requirements:
|
112
|
+
- - ! '>='
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ! '>='
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: 1.3.5
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 1.8.24
|
124
|
+
signing_key:
|
125
|
+
specification_version: 2
|
126
|
+
summary: Interface for communicating with Loopia's API
|
127
|
+
test_files:
|
128
|
+
- spec/loopiator/client_spec.rb
|
129
|
+
- spec/loopiator/credits_spec.rb
|
130
|
+
- spec/loopiator/domains_spec.rb
|
131
|
+
- spec/spec_helper.rb
|