mercadolibre/developers-ios_sdk

Name: developers-ios_sdk

Owner: MercadoLibre

Description: ios sdk

Created: 2016-09-29 12:36:31.0

Updated: 2017-12-21 19:02:28.0

Pushed: 2017-01-10 12:24:07.0

Homepage: null

Size: 796

Language: Objective-C

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

MercadoLibre's iOS SDK

This is the official iOS SDK for MercadoLibre's Platform.

How can I install it?

CocoaPods (iOS 8.0 or later)

Step 1: Download CocoaPods

CocoaPods is a dependency manager for Objective-C and Swift, which automates and simplifies the process of using 3rd-party libraries like MercadoPagoSDK in your projects.

CocoaPods is distributed as a ruby gem, and is installed by running the following commands in Terminal.app:

do gem install cocoapods
d setup

Depending on your Ruby installation, you may not have to run as sudo to install the cocoapods gem.

Step 2: Create a Podfile

Project dependencies to be managed by CocoaPods are specified in a file called Podfile. Create this file in the same directory as your Xcode project (.xcodeproj) file:

uch Podfile
en -a Xcode Podfile

You just created the pod file and opened it using Xcode! Ready to add some content to the empty pod file?

Copy and paste the following lines into the TextEdit window:

ce 'https://github.com/CocoaPods/Specs.git'
frameworks!
form :ios, '8.0'
'MeliDevSDK', '~> 0.1.6'

You shouldn?t use TextEdit to edit the pod file because TextEdit likes to replace standard quotes with more graphically appealing quotes. This can cause CocoaPods to get confused and display errors, so it?s best to just use Xcode or another programming text editor.

Step 3: Install Dependencies

Now you can install the dependencies in your project:

$ pod install

From now on, be sure to always open the generated Xcode workspace (.xcworkspace) instead of the project file when building your project:

$ open .xcworkspace

How do I start using it?

In order to start working on SDK, you need to initialize the SDK using the following static method:

eli startSDK: CLIENT_ID_VALUE withRedirectUrl: REDIRECT_URL_VALUE error:&error];

Where:

Authorizing your application with the user

The SDK provides functionallity to authorize your users to use your application with the MercadoLibre credentials. In order to do that, you need to follow these steps:

1 - Ask for an Identity. If it exits, it means that you have already been granted to use the MercadoLibre APIs that require authorization.

2 - In case you don't have an Identity, you should initialize the sdk and start the login's process using the following static methods.

oid) startSDK: (NSString *) clientId withRedirectUrl:(NSString *) redirectUrl error:(NSError **) error;
bjective-c
oid) startLogin: (UIViewController *) clientViewController withSuccesBlock: (void (^)()) successBlock withErrorBlock: (void (^)(NSString *)) errorBlock;

This last method will check if the sdk was initialized. In case it wasn't, a message will be logged saying that you should do it.

If there wasn't any error trying to get an Access Token, the navigation controller will get the control to the Client View Controller.

Making GET calls
Anonymous
ring * result = [Meli get:path error:&error];

or

essBlock successBlock = ^(NSURLSessionTask *task, id responseObject) {
[self parseData:responseObject];


ureBlock failureBlock = ^(NSURLSessionTask *operation, NSError *error) {
if(error) {
    [self processError:operation error:error];
}


i get:path successBlock:successBlock failureBlock:failureBlock];
Authenticated
ring * result = [Meli getAuth:path withIdentity: [Meli getIdentity] error: &error];

or

essBlock successBlock = ^(NSURLSessionTask *task, id responseObject) {
[self parseData:responseObject];


ureBlock failureBlock = ^(NSURLSessionTask *operation, NSError *error) {
if(error) {
    [self processError:operation error:error];
}


i asyncGetAuth:path withIdentity: identity successBlock:successBlock failureBlock:failureBlock];
Making POST calls
ring * result = [Meli post:path withBody:[self createJsonDataForPost] withIdentity: [Meli getIdentity] error:&error];
or
cHttpOperationBlock operationBlock = ^(NSURLResponse * _Nonnull response, id  _Nullable responseObject, NSError * _Nullable error) {
    if (!error) {
        NSLog(@"Response: %@", responseObject);
    } else {
        NSLog(@"Error: %@, %@, %@", error, response, responseObject);
    }
};

i asyncPost:path withBody:body withIdentity: [Meli getIdentity] operationBlock:operationBlock];
Making PUT calls
ring * result = [Meli put:path withBody:jsonData error:&error];
or
cHttpOperationBlock operationBlock = ^(NSURLResponse * _Nonnull response, id  _Nullable responseObject, NSError * _Nullable error) {
    if (!error) {
        NSLog(@"Response: %@", responseObject);
    } else {
        NSLog(@"Error: %@, %@, %@", error, response, responseObject);
    }
};

i put:path withBody:[self createJsonDataForPut] withIdentity: [Meli getIdentity] error:&error];
Making DELETE calls
Note: In the DELETE example code you will notice that it tries to delete a question. So, if you are going to create a question, it should check that the item does not belong to the same user. Otherwise, you will receive an error from MercadoLibre API.
ring * result = [Meli delete:path withIdentity: [Meli getIdentity] error:&error];
or
essBlock successBlock = ^(NSURLSessionTask *task, id responseObject) {
[self parseData:responseObject];


ureBlock failureBlock = ^(NSURLSessionTask *operation, NSError *error) {
if(error) {
    [self processError:operation error:error];
}


i asyncDelete:path withIdentity: [Meli getIdentity] successBlock:successBlock failureBlock:failureBlock];
Examples

Within the code in the Github repository, there is an example project that contains examples of how to use the SDK.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.