<commit_before># Oauth Client

To access most endpoints you need an oauth client that makes requests using an oauth_consumer_key. This is automatically created when you:

- Create a user
- Login as a user
- Refresh access with a refresh_token

But if you ever need to create a new one using an existing oauth_consumer_key you can with the following code:

```ruby
client = SynapsePay::Client.new("oauth_consumer_key", "refresh_token")

# The refresh token is optional, but if you provide it you can refresh with no extra arguments:
client.refresh_access
```

# User

## Create a user

```ruby
# Make sure we are in Sandbox
SynapsePay.api_base = SynapsePay.api_sandbox

SynapsePay.client_id = "client-id"
SynapsePay.client_secret = "client-secret"

# This creates an oauth client for the newly created user.
client = SynapsePay::User.create({
  :email => "<EMAIL>",
  :fullname => "<NAME>",
  :ip_address => "11.111.11.11",
  :phonenumber => "123456789"
})
```

## Create a user with force_create = "no"

This will return an existing user instead of throwing an error if one exists.

```ruby
# Make sure we are in Sandbox
SynapsePay.api_base = SynapsePay.api_sandbox

SynapsePay.client_id = "client-id"
SynapsePay.client_secret = "client-secret"

# This creates an oauth client for the newly created user.
client = SynapsePay::User.create({
  :email => "<EMAIL>",
  :fullname => "<NAME>",
  :ip_address => "11.111.11.11",
  :phonenumber => "123456789",
  :force_create => "no"
})
```


## Login as a user

```ruby
# Make sure we are in Sandbox
SynapsePay.api_base = SynapsePay.api_sandbox

SynapsePay.client_id = "client-id"
SynapsePay.client_secret = "client-secret"

# Returns an oauth client for this user
client = SynapsePay::User.login("username", "password")
```


## Refresh access

```ruby
# Make sure we are in Sandbox
SynapsePay.api_base = SynapsePay.api_sandbox

SynapsePay.client_id = "client-id"
SynapsePay.client_secret = "client-secret"

client = SynapsePay::Client.refresh_access("refresh-token")

# Alternatively, if you already have a client:
client.refresh_access
```


## Update a user

```ruby
# Make sure we are in Sandbox
SynapsePay.api_base = SynapsePay.api_sandbox

SynapsePay.client_id = "client-id"
SynapsePay.client_secret = "client-secret"
client = SynapsePay::User.login("username", "password")

user = client.user.update({
  :fullname => "new fullname",
  # :new_password => "<PASSWORD>",
  :secret_note => "some secret note"
})

# If you already have a user object:
user.update({
  :fullname => "<NAME>"
})
```


## Retrieve a user

```ruby
# Make sure we are in Sandbox
SynapsePay.api_base = SynapsePay.api_sandbox

SynapsePay.client_id = "client-id"
SynapsePay.client_secret = "client-secret"
client = SynapsePay::User.login("username", "password")

user = client.user.retrieve

# If you already have a user object, you can refresh:
user.refresh
```


## Search users

```ruby
# Make sure we are in Sandbox
SynapsePay.api_base = SynapsePay.api_sandbox

SynapsePay.client_id = "client-id"
SynapsePay.client_secret = "client-secret"
client = SynapsePay::User.login("username", "password")

users = client.user.search("test")
```


# Bank Account

## Link a bank account

```ruby
# Make sure we are in Sandbox
SynapsePay.api_base = SynapsePay.api_sandbox

SynapsePay.client_id = "client-id"
SynapsePay.client_secret = "client-secret"
client = SynapsePay::User.login("username", "password")

# Without an MFA
banks = client.banks.link({
  :username => "synapse_nomfa",
  :password => "<PASSWORD>",
  :bank => "Bank of America"
})
banks # this will be a list of bank accounts

# With a device based MFA
mfa = client.banks.link({
  :username => "synapse_code",
  :password => "<PASSWORD>",
  :bank => "Bank of America"
})
mfa # this will be a SynapsePay::BankMfaDevice instance
banks = mfa.answer("Bank of America", "test_answer") # this will be a list of bank accounts

# With a question based MFA
mfa = client.banks.link({
  :username => "synapse_good",
  :password => "<PASSWORD>",
  :bank => "Bank of America"
})
mfa # this will be a SynapsePay::BankMfaQuestions instance
banks = mfa.answer("Bank of America", "test_answer") # this will be a list of bank accounts
```


## Retrieve a bank account

```ruby
# Make sure we are in Sandbox
SynapsePay.api_base = SynapsePay.api_sandbox

SynapsePay.client_id = "client-id"
SynapsePay.client_secret = "client-secret"
client = SynapsePay::User.login("username", "password")

banks = client.banks.retrieve("2174")
```
<commit_msg>Added samples for #6<commit_after># Oauth Client

To access most endpoints you need an oauth client that makes requests using an oauth_consumer_key. This is automatically created when you:

- Create a user
- Login as a user
- Refresh access with a refresh_token

But if you ever need to create a new one using an existing oauth_consumer_key you can with the following code:

```ruby
client = SynapsePay::Client.new("oauth_consumer_key", "refresh_token")

# The refresh token is optional, but if you provide it you can refresh with no extra arguments:
client.refresh_access
```

# User

## Create a user

```ruby
# Make sure we are in Sandbox
SynapsePay.api_base = SynapsePay.api_sandbox

SynapsePay.client_id = "client-id"
SynapsePay.client_secret = "client-secret"

# This creates an oauth client for the newly created user.
client = SynapsePay::User.create({
  :email => "<EMAIL>",
  :fullname => "<NAME>",
  :ip_address => "11.111.11.11",
  :phonenumber => "123456789"
})
```

## Create a user with force_create = "no"

This will return an existing user instead of throwing an error if one exists.

```ruby
# Make sure we are in Sandbox
SynapsePay.api_base = SynapsePay.api_sandbox

SynapsePay.client_id = "client-id"
SynapsePay.client_secret = "client-secret"

# This creates an oauth client for the newly created user.
client = SynapsePay::User.create({
  :email => "<EMAIL>",
  :fullname => "<NAME>",
  :ip_address => "11.111.11.11",
  :phonenumber => "123456789",
  :force_create => "no"
})
```


## Login as a user

```ruby
# Make sure we are in Sandbox
SynapsePay.api_base = SynapsePay.api_sandbox

SynapsePay.client_id = "client-id"
SynapsePay.client_secret = "client-secret"

# Returns an oauth client for this user
client = SynapsePay::User.login("username", "password")
```


## Refresh access

```ruby
# Make sure we are in Sandbox
SynapsePay.api_base = SynapsePay.api_sandbox

SynapsePay.client_id = "client-id"
SynapsePay.client_secret = "client-secret"

client = SynapsePay::Client.refresh_access("refresh-token")

# Alternatively, if you already have a client:
client.refresh_access
```


## Update a user

```ruby
# Make sure we are in Sandbox
SynapsePay.api_base = SynapsePay.api_sandbox

SynapsePay.client_id = "client-id"
SynapsePay.client_secret = "client-secret"
client = SynapsePay::User.login("username", "password")

user = client.user.update({
  :fullname => "new fullname",
  # :new_password => "<PASSWORD>",
  :secret_note => "some secret note"
})

# If you already have a user object:
user.update({
  :fullname => "<NAME>"
})
```


## Retrieve a user

```ruby
# Make sure we are in Sandbox
SynapsePay.api_base = SynapsePay.api_sandbox

SynapsePay.client_id = "client-id"
SynapsePay.client_secret = "client-secret"
client = SynapsePay::User.login("username", "password")

user = client.user.retrieve

# If you already have a user object, you can refresh:
user.refresh
```


## Search users

```ruby
# Make sure we are in Sandbox
SynapsePay.api_base = SynapsePay.api_sandbox

SynapsePay.client_id = "client-id"
SynapsePay.client_secret = "client-secret"
client = SynapsePay::User.login("username", "password")

users = client.user.search("test")
```


# Bank Account

## Link a bank account

```ruby
# Make sure we are in Sandbox
SynapsePay.api_base = SynapsePay.api_sandbox

SynapsePay.client_id = "client-id"
SynapsePay.client_secret = "client-secret"
client = SynapsePay::User.login("username", "password")

# Without an MFA
banks = client.banks.link({
  :username => "synapse_nomfa",
  :password => "<PASSWORD>",
  :bank => "Bank of America"
})
banks # this will be a list of bank accounts

# With a device based MFA
mfa = client.banks.link({
  :username => "synapse_code",
  :password => "<PASSWORD>",
  :bank => "Bank of America"
})
mfa # this will be a SynapsePay::BankMfaDevice instance
banks = mfa.answer("Bank of America", "test_answer") # this will be a list of bank accounts

# With a question based MFA
mfa = client.banks.link({
  :username => "synapse_good",
  :password => "<PASSWORD>",
  :bank => "Bank of America"
})
mfa # this will be a SynapsePay::BankMfaQuestions instance
banks = mfa.answer("Bank of America", "test_answer") # this will be a list of bank accounts

# Answering an MFA without an MFA instance
banks = client.bank_mfa_devices.answer("access_token, "bank name", "answer")
# or
banks = client.bank_mfa_questions.answer("access_token, "bank name", "answer")
```


## Retrieve a bank account

```ruby
# Make sure we are in Sandbox
SynapsePay.api_base = SynapsePay.api_sandbox

SynapsePay.client_id = "client-id"
SynapsePay.client_secret = "client-secret"
client = SynapsePay::User.login("username", "password")

banks = client.banks.retrieve("2174")
```

{'fraction_non_alphanumeric': 0.12684461805555555, 'fraction_numerical': 0.0087890625, 'mean_word_length': 4.844641724793912, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3888765', 'n_tokens_mistral': 3239, 'n_tokens_neox': 3007, 'n_words': 921}