Skip to content

Commit

Permalink
test authentication script in sandbox/
Browse files Browse the repository at this point in the history
  • Loading branch information
allolex committed May 30, 2012
1 parent e8cd294 commit f475e3c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ spec/reports
test/tmp
test/version_tmp
tmp
credentials
1 change: 1 addition & 0 deletions .rvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rvm use 1.9.3@brightpearl
40 changes: 40 additions & 0 deletions sandbox/brightpearl-test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env ruby

require 'json'
require 'rest_client'

cred_file = File.join(File.dirname(__FILE__),'../credentials/test')

@credentials = []

def load_creds cred_file
fail "Credentials file missing at #{cred_file}" unless File.exists?(cred_file)
@credentials = File.open(cred_file,'r').readlines.each.map(&:chomp)
if @credentials.length == 3
return true
else
return false
end
end

if load_creds cred_file
# The Brightperl data centre code. See
# http://www.brightpearl.com/developer/latest/concept/uri-syntax.html
dc_code = 'eu1'
account_id = @credentials[0]

uri = URI.parse( "https://ws-%s.brightpearl.com/%s/authorise" % [dc_code, account_id] )

message = {
apiAccountCredentials: {
emailAddress: @credentials[1],
password: @credentials[2]
}
}.to_json

response = RestClient.post uri.to_s, message, :content_type => :json, :accept => :json

p response.to_s
else
fail "Invalid credentials file #{cred_file}"
end

0 comments on commit f475e3c

Please sign in to comment.