Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Return all base params for a post

  • Loading branch information...
commit fc119ff9a5c5308a1f7479e819cd1744c94cd4de 1 parent a88c0c6
@alloy alloy authored
Showing with 85 additions and 0 deletions.
  1. +34 −0 lib/mollie/sms.rb
  2. +51 −0 spec/sms_spec.rb
View
34 lib/mollie/sms.rb
@@ -1,5 +1,39 @@
+require "digest/md5"
+
module Mollie
class SMS
+ GATEWAYS = {
+ :basic => 2,
+ :business => 4,
+ :business_plus => 1,
+ :landline => 8
+ }
+
+ class << self
+ attr_accessor :username, :password, :charset, :type, :return_charged_amount, :gateway
+
+ def password=(password)
+ @password = Digest::MD5.hexdigest(password)
+ end
+
+ def request_params
+ params = {
+ :username => @username,
+ :md5_password => @password,
+ :gateway => @gateway,
+ :charset => @charset,
+ :type => :normal
+ }
+ params[:return] = "charged" if @return_charged_amount
+ params
+ end
+ end
+
+ self.charset = 'UTF-8'
+ self.type = :normal
+ self.gateway = GATEWAYS[:basic]
+ self.return_charged_amount = true
+
attr_accessor :telephone_number, :body
end
end
View
51 spec/sms_spec.rb
@@ -1,7 +1,54 @@
require File.expand_path("../spec_helper", __FILE__)
require "mollie/sms"
+Mollie::SMS.username = 'AstroRadio'
+Mollie::SMS.password = 'secret'
+
describe "Mollie::SMS" do
+ it "holds the service username" do
+ Mollie::SMS.username.should == 'AstroRadio'
+ end
+
+ it "holds the service password as a MD5 hashed version" do
+ Mollie::SMS.password.should == Digest::MD5.hexdigest('secret')
+ end
+
+ it "returns the default charset" do
+ Mollie::SMS.charset.should == 'UTF-8'
+ end
+
+ it "returns the default message type" do
+ Mollie::SMS.type.should == :normal
+ end
+
+ it "returns whether or not to return the amount charged" do
+ Mollie::SMS.return_charged_amount.should == true
+ end
+
+ it "holds a list of available gateways" do
+ Mollie::SMS::GATEWAYS[:basic].should == 2
+ Mollie::SMS::GATEWAYS[:business].should == 4
+ Mollie::SMS::GATEWAYS[:business_plus].should == 1
+ Mollie::SMS::GATEWAYS[:landline].should == 8
+ end
+
+ it "returns the default gateway to use" do
+ Mollie::SMS.gateway.should == Mollie::SMS::GATEWAYS[:basic]
+ end
+
+ it "returns a hash of params for a request" do
+ Mollie::SMS.request_params.should == {
+ :username => 'AstroRadio',
+ :md5_password => Mollie::SMS.password,
+ :gateway => 2,
+ :charset => 'UTF-8',
+ :return => 'charged',
+ :type => :normal
+ }
+ end
+end
+
+describe "A Mollie::SMS instance" do
before do
@sms = Mollie::SMS.new
@sms.telephone_number = '+31612345678'
@@ -15,4 +62,8 @@
it "returns the message body" do
@sms.body.should == "The stars tell me you will have chicken noodle soup for breakfast."
end
+
+ #it "returns the POST request body" do
+ #@sms.post_body.should ==
+ #end
end
Please sign in to comment.
Something went wrong with that request. Please try again.