Class: Synapse::Client
- Inherits:
-
Object
- Object
- Synapse::Client
- Defined in:
- lib/synapse_api/client.rb
Overview
header values
Constant Summary collapse
- VALID_QUERY_PARAMS =
[:query, :page, :per_page, :full_dehydrate, :radius, :zip, :lat, :lon, :limit, :currency, :ticker_symbol].freeze
Instance Attribute Summary collapse
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#http_client ⇒ Object
(also: #client)
Returns the value of attribute http_client.
Instance Method Summary collapse
-
#address_verification(payload:) ⇒ Object
Queries Synapse API for Address Verification.
-
#create_subscriptions(scope:, **options) ⇒ Synapse::Subscription
Queries Synapse API to create a webhook subscriptions for platform.
-
#create_user(payload:, ip_address:, **options) ⇒ Synapse::User
Queries Synapse API to create a new user.
-
#get_all_institutions(**options) ⇒ Object
Queries Synapse API for all institutions available for bank logins.
-
#get_all_nodes(**options) ⇒ Array<Synapse::Nodes>
Queries Synapse API for all nodes belonging to platform.
-
#get_all_subscriptions(**options) ⇒ Array<Synapse::Subscriptions>
Queries Synapse API for all platform subscriptions.
-
#get_all_transaction(**options) ⇒ Array<Synapse::Transactions>
Queries Synapse for all transactions on platform.
-
#get_crypto_market_data(**options) ⇒ Object
Queries Synapse API for Crypto Currencies Market data.
-
#get_crypto_quotes ⇒ Object
Queries Synapse API for Crypto Currencies Quotes.
-
#get_subscription(subscription_id:) ⇒ Synapse::Subscription
Queries Synapse API for a subscription by subscription_id.
-
#get_trade_market_data(**options) ⇒ Object
Queries Synapse API for Trade Market data.
- #get_user(user_id:, **options) ⇒ Synapse::User
-
#get_users(**options) ⇒ Array<Synapse::Users>
users with matching name/email.
-
#initialize(client_id:, client_secret:, ip_address:, fingerprint: nil, development_mode: true, raise_for_202: nil, **options) ⇒ Client
constructor
A new instance of Client.
- #issue_public_key(scope:, user_id: nil) ⇒ Object
-
#locate_atm(**options) ⇒ Hash
Queries Synapse API for ATMS nearby.
-
#routing_number_verification(payload:) ⇒ Object
Queries Synapse API for Routing Verification.
-
#update_headers(fingerprint: nil, idemopotency_key: nil, ip_address: nil) ⇒ Object
Update headers in HTTPClient class for API request headers.
-
#update_subscriptions(subscription_id:, body:) ⇒ Synapse::Subscription
Updates subscription platform subscription see docs.synapsefi.com/docs/update-subscription.
-
#webhook_logs(**options) ⇒ Hash
Returns all of the webhooks belonging to client.
Constructor Details
#initialize(client_id:, client_secret:, ip_address:, fingerprint: nil, development_mode: true, raise_for_202: nil, **options) ⇒ Client
Returns a new instance of Client.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/synapse_api/client.rb', line 26 def initialize(client_id:, client_secret:, ip_address:, fingerprint:nil,development_mode: true, raise_for_202:nil, **) base_url = if development_mode 'https://uat-api.synapsefi.com/v3.1' else 'https://api.synapsefi.com/v3.1' end @client_id = client_id @client_secret = client_secret @http_client = HTTPClient.new(base_url: base_url, client_id: client_id, client_secret: client_secret, fingerprint: fingerprint, ip_address: ip_address, raise_for_202: raise_for_202, ** ) end |
Instance Attribute Details
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
13 14 15 |
# File 'lib/synapse_api/client.rb', line 13 def client_id @client_id end |
#http_client ⇒ Object Also known as: client
Returns the value of attribute http_client.
11 12 13 |
# File 'lib/synapse_api/client.rb', line 11 def http_client @http_client end |
Instance Method Details
#address_verification(payload:) ⇒ Object
Queries Synapse API for Address Verification
345 346 347 348 349 350 |
# File 'lib/synapse_api/client.rb', line 345 def address_verification(payload:) path = '/address-verification' response = client.post(path,payload) response end |
#create_subscriptions(scope:, **options) ⇒ Synapse::Subscription
Queries Synapse API to create a webhook subscriptions for platform
190 191 192 193 194 |
# File 'lib/synapse_api/client.rb', line 190 def create_subscriptions(scope:, **) response = client.post(subscriptions_path , scope, ) Subscription.new(subscription_id: response["_id"], url: response["url"], payload: response) end |
#create_user(payload:, ip_address:, **options) ⇒ Synapse::User
Queries Synapse API to create a new user
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/synapse_api/client.rb', line 51 def create_user(payload:, ip_address:, **) client.update_headers(ip_address: ip_address, fingerprint: [:fingerprint]) response = client.post(user_path,payload, ) User.new(user_id: response['_id'], refresh_token: response['refresh_token'], client: client, full_dehydrate: "no", payload: response ) end |
#get_all_institutions(**options) ⇒ Object
Queries Synapse API for all institutions available for bank logins
181 182 183 |
# File 'lib/synapse_api/client.rb', line 181 def get_all_institutions(**) client.get(institutions_path()) end |
#get_all_nodes(**options) ⇒ Array<Synapse::Nodes>
Queries Synapse API for all nodes belonging to platform
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/synapse_api/client.rb', line 154 def get_all_nodes(**) [[:page], [:per_page]].each do |arg| if arg && (!arg.is_a?(Integer) || arg < 1) raise ArgumentError, "#{arg} must be nil or an Integer >= 1" end end path = nodes_path(options: ) nodes = client.get(path) return [] if nodes["nodes"].empty? response = nodes["nodes"].map { |node_data| Node.new(node_id: node_data['_id'], user_id: node_data['user_id'], payload: node_data, full_dehydrate: "no" )} Nodes.new(limit: nodes["limit"], page: nodes["page"], page_count: nodes["page_count"], nodes_count: nodes["node_count"], payload: response ) end |
#get_all_subscriptions(**options) ⇒ Array<Synapse::Subscriptions>
Queries Synapse API for all platform subscriptions
200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/synapse_api/client.rb', line 200 def get_all_subscriptions(**) subscriptions = client.get(subscriptions_path()) return [] if subscriptions["subscriptions"].empty? response = subscriptions["subscriptions"].map { |subscription_data| Subscription.new(subscription_id: subscription_data["_id"], url: subscription_data["url"], payload: subscription_data)} Subscriptions.new(limit: subscriptions["limit"], page: subscriptions["page"], page_count: subscriptions["page_count"], subscriptions_count: subscriptions["subscription_count"], payload: response ) end |
#get_all_transaction(**options) ⇒ Array<Synapse::Transactions>
Queries Synapse for all transactions on platform
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/synapse_api/client.rb', line 129 def get_all_transaction(**) path = '/trans' params = VALID_QUERY_PARAMS.map do |p| [p] ? "#{p}=#{[p]}" : nil end.compact path += '?' + params.join('&') if params.any? trans = client.get(path) return [] if trans["trans"].empty? response = trans["trans"].map { |trans_data| Transaction.new(trans_id: trans_data['_id'], payload: trans_data)} Transactions.new(limit: trans["limit"], page: trans["page"], page_count: trans["page_count"], trans_count: trans["trans_count"], payload: response ) end |
#get_crypto_market_data(**options) ⇒ Object
Queries Synapse API for Crypto Currencies Market data
303 304 305 306 307 308 309 310 311 312 313 314 |
# File 'lib/synapse_api/client.rb', line 303 def get_crypto_market_data(**) path = '/nodes/crypto-market-watch' params = VALID_QUERY_PARAMS.map do |p| [p] ? "#{p}=#{[p]}" : nil end.compact path += '?' + params.join('&') if params.any? data = client.get(path) data end |
#get_crypto_quotes ⇒ Object
Queries Synapse API for Crypto Currencies Quotes
288 289 290 291 292 293 294 295 296 297 |
# File 'lib/synapse_api/client.rb', line 288 def get_crypto_quotes() path = '/nodes/crypto-quotes' params = VALID_QUERY_PARAMS.map do |p| [p] ? "#{p}=#{[p]}" : nil end.compact path += '?' + params.join('&') if params.any? quotes = client.get(path) quotes end |
#get_subscription(subscription_id:) ⇒ Synapse::Subscription
Queries Synapse API for a subscription by subscription_id
218 219 220 221 222 |
# File 'lib/synapse_api/client.rb', line 218 def get_subscription(subscription_id:) path = subscriptions_path + "/#{subscription_id}" response = client.get(path) Subscription.new(subscription_id: response["_id"], url: response["url"], payload: response) end |
#get_trade_market_data(**options) ⇒ Object
Queries Synapse API for Trade Market data
319 320 321 322 323 324 325 326 327 328 329 330 |
# File 'lib/synapse_api/client.rb', line 319 def get_trade_market_data(**) path = '/nodes/trade-market-watch' params = VALID_QUERY_PARAMS.map do |p| [p] ? "#{p}=#{[p]}" : nil end.compact path += '?' + params.join('&') if params.any? market_data = client.get(path) market_data end |
#get_user(user_id:, **options) ⇒ Synapse::User
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/synapse_api/client.rb', line 80 def get_user(user_id:, **) raise ArgumentError, 'client must be a Synapse::Client' unless self.is_a?(Client) raise ArgumentError, 'user_id must be a String' unless user_id.is_a?(String) [:full_dehydrate] = "yes" if [:full_dehydrate] == true [:full_dehydrate] = "no" if [:full_dehydrate] == false client.update_headers(ip_address: [:ip_address], fingerprint: [:fingerprint]) path = user_path(user_id: user_id, full_dehydrate: [:full_dehydrate]) response = client.get(path) User.new(user_id: response['_id'], refresh_token: response['refresh_token'], client: client, full_dehydrate: [:full_dehydrate] == "yes" ? true : false, payload: response ) end |
#get_users(**options) ⇒ Array<Synapse::Users>
users with matching name/email
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/synapse_api/client.rb', line 106 def get_users(**) path = user_path() response = client.get(path) return [] if response["users"].empty? users = response["users"].map { |user_data| User.new(user_id: user_data['_id'], refresh_token: user_data['refresh_token'], client: client, full_dehydrate: "no", payload: user_data )} Users.new(limit: response["limit"], page: response["page"], page_count: response["page_count"], user_count: response["users_count"], payload: users, http_client: client ) end |
#issue_public_key(scope:, user_id: nil) ⇒ Object
valid scope “OAUTH|POST,USERS|POST,USERS|GET,USER|GET,USER|PATCH,SUBSCRIPTIONS|GET,SUBSCRIPTIONS|POST,SUBSCRIPTION|GET,SUBSCRIPTION|PATCH,CLIENT|REPORTS,CLIENT|CONTROLS”
257 258 259 260 261 262 263 264 265 266 |
# File 'lib/synapse_api/client.rb', line 257 def issue_public_key(scope:, user_id: nil) path = '/client?issue_public_key=YES' path += "&scope=#{scope}" path += "&user_id=#{user_id}" if user_id response = client.get(path) response[ "public_key_obj"] end |
#locate_atm(**options) ⇒ Hash
Queries Synapse API for ATMS nearby
275 276 277 278 279 280 281 282 283 284 |
# File 'lib/synapse_api/client.rb', line 275 def locate_atm(**) params = VALID_QUERY_PARAMS.map do |p| [p] ? "#{p}=#{[p]}" : nil end.compact path = "/nodes/atms?" path += params.join('&') if params.any? atms = client.get(path) atms end |
#routing_number_verification(payload:) ⇒ Object
Queries Synapse API for Routing Verification
335 336 337 338 339 340 |
# File 'lib/synapse_api/client.rb', line 335 def routing_number_verification(payload:) path = '/routing-number-verification' response = client.post(path,payload) response end |
#update_headers(fingerprint: nil, idemopotency_key: nil, ip_address: nil) ⇒ Object
Update headers in HTTPClient class for API request headers
69 70 71 |
# File 'lib/synapse_api/client.rb', line 69 def update_headers(fingerprint:nil, idemopotency_key:nil, ip_address:nil) client.update_headers(fingerprint: fingerprint, idemopotency_key: idemopotency_key, ip_address: ip_address) end |
#update_subscriptions(subscription_id:, body:) ⇒ Synapse::Subscription
Updates subscription platform subscription see docs.synapsefi.com/docs/update-subscription
229 230 231 232 233 234 |
# File 'lib/synapse_api/client.rb', line 229 def update_subscriptions(subscription_id:, body:) path = subscriptions_path + "/#{subscription_id}" response = client.patch(path, body) Subscription.new(subscription_id: response["_id"], url: response["url"], payload: response) end |
#webhook_logs(**options) ⇒ Hash
Returns all of the webhooks belonging to client
240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/synapse_api/client.rb', line 240 def webhook_logs(**) path = subscriptions_path + "/logs" params = VALID_QUERY_PARAMS.map do |p| [p] ? "#{p}=#{[p]}" : nil end.compact path += '?' + params.join('&') if params.any? client.get(path) end |