<commit_before>#### Env variables

As you may have seen in the conf.py file, 3 variables ar needed to use the Iceperg python API: the Iceberg private key, the Iceberg secret key and the application namespace. These variables must be initiated as environment variables. For security purposes we're gonna load them in a seperate file. Let's create a env.sh file in the root folder containing the following lines.

<pre>
export ICEBERG_API_PRIVATE_KEY=XXXXXX
export ICEBERG_APPLICATION_NAMESPACE=my_app
export ICEBERG_APPLICATION_SECRET_KEY=XXXXXX
</pre>

Theses variables must now be loaded in the environment using 
<pre>source env_setup.sh</pre>
* * *

#### Log in 

For many of the API operations, we need to be logged in as a user (as a staff user or not). So let's create a logIn function we are gonna call everytime we need to.

<pre>

def logIn():
    api_handler = IcebergAPI()
    api_handler.sso("userEmail","userFirstName","userLastName")
    return api_handler

</pre>
* * *

#### Get infos of a specific offer

Let's fetch some specific informations about an offer, display the image url, description, and get stock, size and price for each variation. 

<pre>

#fetch offer object width the product ID
product = api_handler.ProductOffer.find("52")

#print infos
print product.default_image_url
print product.description
for variation in product.variations:
    print "%s items available in size %s, %s euros" %(variation['stock'],variation['name'],variation['price'])

</pre>
* * *

#### Add product to cart

These few lines of code show you how to simply add a product to a specific user's cart, don't forget to pass the 4 required arguments.

<pre>

#Initialize the API and log in
api_handler = logIn()

#Get cart
user_cart = api_handler.Cart.mine()

#fetch offer object width the product ID
product = api_handler.ProductOffer.find("52")

#print propreties of the product you just found
print product.description
print product.price_with_vat

#Add offer to the logged user's cart
user_cart.addOffer(product)

#print total amount of the cart
print api_handler.Cart.mine().total_amount
    
</pre>
* * *


#### Get infos of a user's cart

Let's retrieve a user's cart object and display its shipping_adress, shipping amount and total amount.

<pre>

#Initialize the API and log in
api_handler = logIn()

#cart object
user_cart = api_handler.Cart.mine()

#print infos
print user_cart.shipping_address
print user_cart.shipping_amount
print user_cart.total_amount
    
</pre>
* * *


#### Get user infos

Retrieve specific infos about a user

<pre>

#Initialize the API and log in
api_handler = logIn()

me = api_handler.User.me()

#print me.to_JSON()
print me.username
print me.first_name
print me.last_name
print me.email
print me.timezone

</pre>
* * *


#### Get store infos

Retrieve infos about a store in the application. We are gonna look for the store number 11 and display infos about it. This number is allocated automatically by Iceberg, you can find your stores's IDs in the get request's response on the "merchant" section.

<pre>

api_handler = IcebergAPI()

store = api_handler.Store.find(11)

print store.name
print store.created_on
print store.long_description
print store.url

</pre>


<commit_msg>readme #5<commit_after>#### Env variables

As you may have seen in the conf.py file, 3 variables ar needed to use the Iceperg python API: the Iceberg private key, the Iceberg secret key and the application namespace. These variables must be initiated as environment variables. For security purposes we're gonna load them in a seperate file. Let's create a env.sh file in the root folder containing the following lines.

```python
export ICEBERG_API_PRIVATE_KEY=XXXXXX
export ICEBERG_APPLICATION_NAMESPACE=my_app
export ICEBERG_APPLICATION_SECRET_KEY=XXXXXX
```

Theses variables must now be loaded in the environment using 
<pre>source env_setup.sh</pre>
* * *

#### Log in 

For many of the API operations, we need to be logged in as a user (as a staff user or not). So let's create a logIn function we are gonna call everytime we need to.

```python

def logIn():
    api_handler = IcebergAPI()
    api_handler.sso("userEmail","userFirstName","userLastName")
    return api_handler

```
* * *

#### Get infos of a specific offer

Let's fetch some specific informations about an offer, display the image url, description, and get stock, size and price for each variation. 

```python

#fetch offer object width the product ID
product = api_handler.ProductOffer.find("52")

#print infos
print product.default_image_url
print product.description
for variation in product.variations:
    print "%s items available in size %s, %s euros" %(variation['stock'],variation['name'],variation['price'])

```
* * *

#### Add product to cart

These few lines of code show you how to simply add a product to a specific user's cart, don't forget to pass the 4 required arguments.

```python

#Initialize the API and log in
api_handler = logIn()

#Get cart
user_cart = api_handler.Cart.mine()

#fetch offer object width the product ID
product = api_handler.ProductOffer.find("52")

#print propreties of the product you just found
print product.description
print product.price_with_vat

#Add offer to the logged user's cart
user_cart.addOffer(product)

#print total amount of the cart
print api_handler.Cart.mine().total_amount
    
```
* * *


#### Get infos of a user's cart

Let's retrieve a user's cart object and display its shipping_adress, shipping amount and total amount.

```python

#Initialize the API and log in
api_handler = logIn()

#cart object
user_cart = api_handler.Cart.mine()

#print infos
print user_cart.shipping_address
print user_cart.shipping_amount
print user_cart.total_amount
    
```
* * *


#### Get user infos

Retrieve specific infos about a user

```python

#Initialize the API and log in
api_handler = logIn()

me = api_handler.User.me()

#print me.to_JSON()
print me.username
print me.first_name
print me.last_name
print me.email
print me.timezone

```
* * *


#### Get store infos

Retrieve infos about a store in the application. We are gonna look for the store number 11 and display infos about it. This number is allocated automatically by Iceberg, you can find your stores's IDs in the get request's response on the "merchant" section.

```python

api_handler = IcebergAPI()

store = api_handler.Store.find(11)

print store.name
print store.created_on
print store.long_description
print store.url

```



{'fraction_non_alphanumeric': 0.08244227491089416, 'fraction_numerical': 0.0032543003254300326, 'mean_word_length': 4.597571552471813, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '6451446', 'n_tokens_mistral': 1985, 'n_tokens_neox': 1907, 'n_words': 818}