Module: Trustev
- Defined in:
- lib/trustev.rb,
lib/trustev/error.rb,
lib/trustev/social.rb,
lib/trustev/profile.rb,
lib/trustev/version.rb,
lib/trustev/transaction.rb,
lib/trustev/authenticate.rb,
lib/trustev/digital_signature.rb
Defined Under Namespace
Classes: Authenticate, DigitalSignature, Error, Profile, Social, Transaction
Constant Summary collapse
- ADDRESS_TYPES =
{ standard: 0, billing: 1, delivery: 2 }
- SOCIAL_NETWORK_TYPES =
{ facebook: 0, twitter: 1, linkedin: 2, trustev: 3 }
- STATUS_TYPES =
{ init: 0, placed: 1, refunded: 2, rejected: 3, completed: 5, chargeback: 8 }
- REASON_TYPES =
{ system: 0, fraud: 1, complaint: 2, remorse: 3, other: 4 }
- SCORE_SOURCES =
{ address: 0, behaviour: 1, device: 2, email: 3, facebook: 4, IP: 5, transaction: 6, trustev: 7, velocity: 8 }
- SCORE_PARAMETERS =
{ overall: 0, billing: 1, delivery: 2, input: 3, domain: 4, address: 5, IP: 6, proxy: 7, VPN: 8, value: 9, velocity: 10, legitimacy: 11, pattern: 12, hustle: 13 }
- VERSION =
'0.3.2'- @@username =
nil- @@password =
nilnil- @@private_key =
nil- @@public_key =
nil- @@api_base =
'https://api.trustev.com/v'- @@api_version =
'1.2'- @@token =
nil- @@token_expire =
nil
Class Method Summary collapse
- .api_url(url = '') ⇒ Object
- .password ⇒ Object
- .password=(password) ⇒ Object
- .private_key ⇒ Object
- .private_key=(private_key) ⇒ Object
- .public_key ⇒ Object
- .public_key=(public_key) ⇒ Object
- .send_request(path, body, method, expect_json = false, requires_token = true) ⇒ Object
- .shared_secret ⇒ Object
- .shared_secret=(shared_secret) ⇒ Object
- .token ⇒ Object
- .token=(token) ⇒ Object
- .token_expire ⇒ Object
- .token_expire=(token_expire) ⇒ Object
- .username ⇒ Object
- .username=(username) ⇒ Object
Class Method Details
.api_url(url = '') ⇒ Object
122 123 124 |
# File 'lib/trustev.rb', line 122 def self.api_url(url='') @@api_base + @@api_version + '/' + url end |
.password ⇒ Object
94 95 96 |
# File 'lib/trustev.rb', line 94 def self.password @@password end |
.password=(password) ⇒ Object
90 91 92 |
# File 'lib/trustev.rb', line 90 def self.password=(password) @@password = password end |
.private_key ⇒ Object
110 111 112 |
# File 'lib/trustev.rb', line 110 def self.private_key @@private_key end |
.private_key=(private_key) ⇒ Object
106 107 108 |
# File 'lib/trustev.rb', line 106 def self.private_key=(private_key) @@private_key = private_key end |
.public_key ⇒ Object
118 119 120 |
# File 'lib/trustev.rb', line 118 def self.public_key @@public_key end |
.public_key=(public_key) ⇒ Object
114 115 116 |
# File 'lib/trustev.rb', line 114 def self.public_key=(public_key) @@public_key = public_key end |
.send_request(path, body, method, expect_json = false, requires_token = true) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/trustev.rb', line 142 def self.send_request(path, body, method, expect_json=false, requires_token=true) if requires_token && invalid_token? Authenticate.retrieve_token end raise Error.new('Auth token missing or expired') if requires_token && invalid_token? headers = { 'Content-Type' => 'application/json', 'Accept' => 'application/json' } headers['X-Authorization'] = "#{@@username} #{@@token}" if requires_token body = { request: body } = { body: body.to_json, headers: headers} response = HTTParty.post(api_url(path), ) if method == 'POST' response = HTTParty.get(api_url(path), ) if method == 'GET' response = HTTParty.put(api_url(path), ) if method == 'PUT' response = HTTParty.delete(api_url(path), ) if method == 'DELETE' raise Error.new('Bad API response', response.code, response.) if response.code != 200 if expect_json begin response = MultiJson.load(response.body, symbolize_keys: true) rescue MultiJson::DecodeError raise Error.new('Invalid API response', response.code, response.) end end response end |
.shared_secret ⇒ Object
102 103 104 |
# File 'lib/trustev.rb', line 102 def self.shared_secret @@shared_secret end |
.shared_secret=(shared_secret) ⇒ Object
98 99 100 |
# File 'lib/trustev.rb', line 98 def self.shared_secret=(shared_secret) @@shared_secret = shared_secret end |
.token ⇒ Object
130 131 132 |
# File 'lib/trustev.rb', line 130 def self.token @@token end |
.token=(token) ⇒ Object
126 127 128 |
# File 'lib/trustev.rb', line 126 def self.token=(token) @@token = token end |
.token_expire ⇒ Object
138 139 140 |
# File 'lib/trustev.rb', line 138 def self.token_expire @@token_expire end |
.token_expire=(token_expire) ⇒ Object
134 135 136 |
# File 'lib/trustev.rb', line 134 def self.token_expire=(token_expire) @@token_expire = token_expire end |
.username ⇒ Object
86 87 88 |
# File 'lib/trustev.rb', line 86 def self.username @@username end |
.username=(username) ⇒ Object
82 83 84 |
# File 'lib/trustev.rb', line 82 def self.username=(username) @@username = username end |