Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mavenized Java API #1

Open
wants to merge 170 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
170 commits
Select commit Hold shift + click to select a range
7e9a3ff
Initial commit of swagger api explorer
ianmuninio Nov 20, 2013
67968a0
Initial commit of swagger api explorerInitial commit of nodejs docs
ianmuninio Nov 20, 2013
926c3aa
conformed with the standards
adin234 Nov 20, 2013
37b8f84
payment docs
adin234 Nov 20, 2013
a6f969b
Update the documentation
ianmuninio Nov 20, 2013
16f1f5d
Update the documentation on Figure 12.
ianmuninio Nov 20, 2013
32eb89c
Added new documentation about receiving data.
ianmuninio Nov 20, 2013
af1ac36
Auto parse the received response of the server to object.
ianmuninio Nov 20, 2013
3b3c91f
Update the figure 11.
ianmuninio Nov 20, 2013
f9164e8
Update all the documentations
ianmuninio Nov 20, 2013
5a33f88
Sorted the parameters.
ianmuninio Nov 20, 2013
baab08e
Refactored code and hid isValid() because it's not applicable for pub…
riamaria Nov 21, 2013
2d8bfb0
Fixed wrong condition in ternary operator.
riamaria Nov 21, 2013
14db11f
Updated binary and javadocs to reflect previous changes
riamaria Nov 21, 2013
9f427dc
Transferred binary to lib folder along with its dependencies.
riamaria Nov 21, 2013
3e488cb
Added sample runners for OAuth, SMS, and Payment.
riamaria Nov 21, 2013
fd5ec41
fixed javadocs on the classes
adin234 Nov 21, 2013
83695a1
Merge branch 'master' of https://github.com/globelabs/api
adin234 Nov 21, 2013
4257f9b
sms docs
adin234 Nov 21, 2013
3888d23
changed getAuthUrl to getLoginUrl
adin234 Nov 21, 2013
bb1be82
Update index.php
adin234 Nov 21, 2013
35a7f3a
Removed unnecessary access token POST parameter. Updated binary.
riamaria Nov 21, 2013
301b7b6
Added documentation
riamaria Nov 21, 2013
2b1868e
Changed amount data type from BigDecimal to String because of an upda…
riamaria Nov 21, 2013
699b410
fixed directory inclusion using absolute path. fixed documentations
adin234 Nov 21, 2013
e7305ca
changed the array return
adin234 Nov 21, 2013
0fb7fae
Merge branch 'master' of https://github.com/globelabs/api
adin234 Nov 21, 2013
ea0a6cf
replaced all ocurrences of outh variable in docs to auth
adin234 Nov 21, 2013
bf05045
Delete __init__.py
clark21 Nov 21, 2013
d1aedc0
Delete base.py
clark21 Nov 21, 2013
344cf7a
Delete oauth.py
clark21 Nov 21, 2013
43cecf1
Delete payment.py
clark21 Nov 21, 2013
541e254
Delete sms.py
clark21 Nov 21, 2013
34295a1
Delete test.py
clark21 Nov 21, 2013
51282f1
fixed directory inclusion using absolute path. fixed documentations
Nov 21, 2013
83ea5ea
Merge branch 'master' of https://github.com/globelabs/api
Nov 21, 2013
263f391
Renamed OAuth class to Auth. Updated javadocs, documentation, tests, …
riamaria Nov 22, 2013
bf2444c
Edited README to reflect renaming of OAuth class to Auth.
riamaria Nov 22, 2013
2f11162
Class OAuth changed to Auth
adin234 Nov 22, 2013
32b26c6
Merge branch 'master' of https://github.com/globelabs/api
adin234 Nov 22, 2013
69431cf
Update payment.md
danmolina Nov 22, 2013
9e0553e
Update payment.md
adin234 Nov 22, 2013
b817813
Vanity changes
ianmuninio Nov 22, 2013
55c303a
Merge origin/master
ianmuninio Nov 22, 2013
ab2b3a5
change sms call to sendMessage
adin234 Nov 22, 2013
ab9fb30
Merge branch 'master' of https://github.com/globelabs/api
adin234 Nov 22, 2013
a6c9a62
Update sms.md
adin234 Nov 22, 2013
c19e3fd
Changed SMS methods from send to sendMessage and getSmsResponse to ge…
riamaria Nov 22, 2013
88b6844
Updated javadocs and sample runner to reflect new Globe reference cod…
riamaria Nov 22, 2013
0537a72
removed oauth.php
adin234 Nov 22, 2013
5685149
Merge branch 'master' of https://github.com/globelabs/api
adin234 Nov 22, 2013
afc4de5
Change folder name lib to src
ianmuninio Nov 22, 2013
5b0be16
Merge origin/master
ianmuninio Nov 22, 2013
e8550c9
added Protocol documentation
Nov 22, 2013
1936373
Update Sms.md
danmolina Nov 22, 2013
09e1c8c
Update Payment.md
danmolina Nov 22, 2013
7fd300e
Change all "PROTO" to "JAVA" and change the introduction to specifica…
riamaria Nov 22, 2013
8018dfd
Update the docs.
ianmuninio Nov 22, 2013
bfc58e7
changed the proto to php.payment/sms and fixed the introduction
adin234 Nov 22, 2013
219c567
Specified figure modules and updated introduction.
riamaria Nov 22, 2013
86beb52
Update payment.md
danmolina Nov 22, 2013
6a29492
Update sms.md
danmolina Nov 22, 2013
c2bcd54
remove protocol folder
Nov 22, 2013
f4ac5c9
added payment and sms doc
Nov 22, 2013
e6de64e
Merge branch 'master' of https://github.com/globelabs/api
adin234 Nov 22, 2013
358af9b
remove protocol folder
Nov 22, 2013
3a7fc64
Merge branch 'master' of https://github.com/globelabs/api
adin234 Nov 22, 2013
880f693
Update Payment.md
danmolina Nov 22, 2013
0abc34c
Update payment.md
danmolina Nov 22, 2013
361f75c
changed proto to php.sms/payment
adin234 Nov 22, 2013
43540f3
Merge branch 'master' of https://github.com/globelabs/api
adin234 Nov 22, 2013
52cb7f1
fixed docs
adin234 Nov 22, 2013
1930d76
Update sms.md
danmolina Nov 22, 2013
4a96120
Merge branch 'master' of https://github.com/globelabs/api
adin234 Nov 22, 2013
ceed40e
fixed docs
adin234 Nov 22, 2013
9a79177
Update Payment.md
danmolina Nov 22, 2013
1c8b307
Update payment.md
adin234 Nov 22, 2013
d796a1c
Edited sample charge response to conform to new Globe reference code …
riamaria Nov 22, 2013
b237bfc
Update the introduction
ianmuninio Nov 22, 2013
a37cbdb
Update introduction, figures and documentation.
ianmuninio Nov 22, 2013
107cfba
Update sms.md
adin234 Nov 22, 2013
a77d417
Update sms.md
adin234 Nov 22, 2013
0dc64a7
Update sms.md
adin234 Nov 22, 2013
2f2610a
Update payment.md
adin234 Nov 22, 2013
5deaee4
Update README.md
danmolina Nov 22, 2013
2f75f07
Changed amount String to BigDecimal to cater to new Globe amount form…
riamaria Nov 22, 2013
351019a
Delete Oauth.py
clark21 Nov 22, 2013
91ef503
rename Oauth to Auth
Nov 22, 2013
ccbac0a
Merge branch 'master' of https://github.com/globelabs/api
Nov 22, 2013
8120a8c
Oauth to Auth
Nov 22, 2013
37327de
Update sms.md
danmolina Nov 22, 2013
a62a6c8
Update Payment.md
danmolina Nov 22, 2013
0da1735
Update Sms.md
danmolina Nov 22, 2013
3203309
Update sms.md
adin234 Nov 22, 2013
81306b1
Update payment.md
Nov 22, 2013
5e12121
Added required transactionOperationStatus for client calls to Globe S…
riamaria Nov 22, 2013
2a3fa01
Update sms.md
Nov 22, 2013
5f83776
Update payment.md
clark21 Nov 22, 2013
db14903
Update sms.md
clark21 Nov 22, 2013
7f3d169
Update sms.md
clark21 Nov 22, 2013
e833e58
Update sms.md
clark21 Nov 22, 2013
115cb2d
Update payment.md
clark21 Nov 22, 2013
ee4b2f6
Update introduction
ianmuninio Nov 22, 2013
a1134df
Update Sample Charge Response
ianmuninio Nov 22, 2013
0a742f5
Update Auth.php
adin234 Nov 22, 2013
f603d4d
add access token handler
Nov 22, 2013
dc3f7f3
Merge branch 'master' of https://github.com/globelabs/api
Nov 22, 2013
82edb59
fixed the sources for the receiving
adin234 Nov 22, 2013
59ec4ca
fixed receive
adin234 Nov 22, 2013
53d3427
Update sms.md
danmolina Nov 22, 2013
6644822
Update Sms.md
danmolina Nov 22, 2013
8353096
Update Sms.md
danmolina Nov 22, 2013
b2f2532
updated the sms class and add a receive sample
Nov 22, 2013
2622d65
Update Payment.rb
danmolina Nov 22, 2013
dc366e3
updated the test script
Nov 22, 2013
6535a62
Merge branch 'master' of https://github.com/globelabs/api
Nov 22, 2013
30ca956
Update receive.rb
danmolina Nov 22, 2013
fc8ae61
add readme file
Nov 22, 2013
c15fd4a
Merge branch 'master' of https://github.com/globelabs/api
Nov 22, 2013
f45e95c
remove readme
Nov 22, 2013
9621d1e
Update sms.md
danmolina Nov 22, 2013
33188b1
Update receive.rb
danmolina Nov 22, 2013
eb43116
add json handler
Nov 22, 2013
6af50c5
add sample receiving code
Nov 22, 2013
88f1eef
Merge branch 'master' of https://github.com/globelabs/api
Nov 22, 2013
6335e6b
Added arguments validation
ianmuninio Nov 22, 2013
1f04ada
Update sms.md
adin234 Nov 23, 2013
b1b38c4
Update sms.md
adin234 Nov 23, 2013
e3d1e6c
Update sms.md
adin234 Nov 23, 2013
8c63d58
Update index.php
adin234 Nov 23, 2013
182812e
Update sms.md
adin234 Nov 23, 2013
df57420
Update sms.md
adin234 Nov 23, 2013
bdc0f7a
Update sms.md
adin234 Nov 23, 2013
df10f79
Update sms.md
adin234 Nov 23, 2013
da6a1c9
Update sms.md
adin234 Nov 23, 2013
15e480f
fixed charge class
adin234 Nov 23, 2013
9fe46c8
updated test
adin234 Nov 23, 2013
cd033fa
update the test for receiving data via post with content type of json
Nov 23, 2013
e0811b4
Update receive.rb
danmolina Nov 23, 2013
100f506
Update test.rb
danmolina Nov 23, 2013
49d0674
Update Sms.rb
danmolina Nov 23, 2013
29616c1
added client correlator
adin234 Nov 23, 2013
f388c8d
Merge branch 'master' of https://github.com/globelabs/api
adin234 Nov 23, 2013
a030dcc
added clientCorrelator
adin234 Nov 23, 2013
cf69698
added desc
adin234 Nov 23, 2013
3d28739
Merge branch 'master' of https://github.com/globelabs/api
Nov 23, 2013
0d81b9d
Changed Sms.getMessage() to support JSON instead of url-encoded forma…
riamaria Nov 29, 2013
1acca42
android class
adin234 Nov 29, 2013
2040747
Update MainActivity.java
adin234 Nov 29, 2013
38345a5
Update sms.md
adin234 Nov 29, 2013
81d60fb
Update sms.md
adin234 Nov 29, 2013
f44bef4
Update sms.md
adin234 Nov 29, 2013
df2442d
Update sms.md
adin234 Nov 29, 2013
a30abe7
added the library
adin234 Nov 29, 2013
f3cf25e
Merge branch 'master' of https://github.com/globelabs/api
adin234 Nov 29, 2013
1c8e806
ios initial commit
adin234 Dec 2, 2013
39b8726
Payment:
ianmuninio Dec 3, 2013
c9998e2
Added clientCorrelator form
ianmuninio Dec 3, 2013
93344c1
Added transactionOperationStatus parameter on charging.
ianmuninio Dec 3, 2013
71c93d5
Added optional clientCorrelator field in sendMessage() via method ove…
riamaria Dec 3, 2013
4faecd2
Add getMessage function for retrieving messages
Dec 3, 2013
335725f
Merge branch 'master' of https://github.com/globelabs/api
adin234 Dec 4, 2013
800766d
added receive function
adin234 Dec 4, 2013
a10d79b
updated the sources and the lib
adin234 Dec 5, 2013
912dd8e
update as of december 2
Dec 6, 2013
b6e8761
Added retrieve messages on swagger
ianmuninio Dec 9, 2013
a915e9c
Merge origin/master
ianmuninio Dec 9, 2013
5e15878
Updated swagger documentation
ianmuninio Dec 10, 2013
6742259
Fixed the headers
ianmuninio Dec 10, 2013
692dae0
Mavenized Java API
edgedalmacio Jun 5, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.idea
.classpath
.project
*.iml
target
20 changes: 20 additions & 0 deletions Android/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright (c) 2013 Aldrin Bautista

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
151 changes: 151 additions & 0 deletions Android/docs/payment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
## Introduction

The Globe Payment API lets you develop client applications to charge subscribers. This document describes how to use the OAUTH/RESTful calling style and client library for PHP.

## Getting Started

The first thing we need to do is obtain an **APP ID** and **APP SECRET** from [Globe's Developer Website](http://developer.globelabs.com.ph/users/login). When visiting the link provided you should see a login form similar to *Figure PHP.PAYMENT.1*.

##### Figure PHP.PAYMENT.1 - Login
![Login Screen](https://raw.github.com/Openovate/rest-docs/master/sms/assets/login.jpg)
====

Currently Globe's RESTful API is in BETA Mode. Ask your local Globe support to gain access to this BETA.

Next, login with your given credentials to get to the APP screen. When you get to the app screen scroll to the bottom right and click the "create" button to create a new app. You should see something familiar to *Figure PHP.PAYMENT.2*

##### Figure PHP.PAYMENT.2 - Create App Button
![Create App Button](https://raw.github.com/Openovate/rest-docs/master/sms/assets/create.jpg)
====

This will bring you to a form with required information that Globe will need to process your app creation. Fill out this form with the required fields at the very least and press Submit found at the bottom right in *Figure PHP.PAYMENT.3*.

##### Figure PHP.PAYMENT.3 - Create App Form
![Create App Form](https://raw.github.com/Openovate/rest-docs/master/sms/assets/form.jpg)
====

**Important:** It's important that the Redirect URI and the Notify URI are using actual
URLs as in http://www.example.com/callback. Globe will call these URLs as described in the field.

From here you should be returned to the APP Detail Page in *Figure PHP.PAYMENT.4*. The important thing here is the **APP ID** and **APP SECRET**. These will be the information that you will need to manually set in the configurations when writing your application.

##### Figure PHP.PAYMENT.4 - App Details
![Create App Form](https://raw.github.com/Openovate/rest-docs/master/sms/assets/detail.jpg)

**Note:** The data in this screen doesn't actually work. Please don't assume something went
wrong because you tried to use it.

## How to Include

First thing before you do any calls for Globe API using PHP wrapper class is to include the base class called GlobeApi.

##### Figure PHP.PAYMENT.5 - Include Base Class

**Note:** To include these you have to point the location of the file and require it in your app. In my case, I am using the test script inside the test folder and it will look like this.

require ('path/to/directory/GlobeApi.php');
$globe = new GlobeApi([version]);

## Authentication

Once we obtain the **APP ID** and **APP SECRET** we can begin to understand how the authentication works. Globe uses [OAUTH2](https://developers.google.com/accounts/docs/OAuth2), a common PHP.PAYMENTcol to authenticate developers to use API PHP.PAYMENTcols. To begin the authentication process you must redirect the user to a formatted URL using your **APP ID** and **APP SECRET** as in *Figure PHP.PAYMENT.6*.

##### Figure PHP.PAYMENT.6 - Invoke a Redirection

Now, initialize the `Auth` class inside GlobeApi and get the login URL using the `getLoginUrl` method.

$auth = $globe->auth(
[YOUR APP ID],
[YOUR APP SECRET]
);
$loginUrl = auth->getLoginUrl();
header('Location: '.$loginUrl);

Before invoking your redirect, please replace `[YOUR APP ID]` and `[YOUR APP SECRET]` in the figure above with your actual **APP ID** and **APP SECRET**. Based on what you inputed as your **Redirect URI** in your app details. Globe will authenticate permissions first with the user which should look like *Figure PHP.PAYMENT.7a* and *Figure PHP.PAYMENT.7b*.

##### Figure PHP.PAYMENT.7a - User Flow
![User Flow](https://raw.github.com/Openovate/rest-docs/master/sms/assets/user.jpg)
====
##### Figure PHP.PAYMENT.7b - Authorize
![Authorize](https://raw.github.com/Openovate/rest-docs/master/sms/assets/user.jpg)
====

Once the user gives permission, Globe will redirect the user to your Redirect URI with a `code` parameter appended to the end of it. This is how we recieve the code to continue the authentication process. *Figure PHP.PAYMENT.8* shows how this redirect will look like given that we set our redirect URI to `http://www.example.com/callback` in our app create form in *Figure PHP.PAYMENT.3*.

**Important:** It is also possible that a user can give permissions to your app using just their
phone via SMS. Globe will call (not a phone call) your redirect URI with `access_token` and
`subscriber_number` appended to the end of it. From here you can process this request and
ignore the rest of the authentication process below.

##### Figure PHP.PAYMENT.8 - Redirected URI Sample

http://www.example.com/callback?code=12345

`12345` in the URL figure above is what we need in order to get a more long lasting token for your app to use when making API calls. Everytime you make this call the `code` returned will be unique, so you should not hard code the `code` value in your application. The final step in the authentication process is about exchanging your `code` with a more permanent access token. We need to send Globe one final request shown in *Figure PHP.PAYMENT.9*

##### Figure PHP.PAYMENT.9 - Get the Access Token

Using the `Auth` object we initialized in **Figure PHP.PAYMENT.6**, we can get the access token using the script below.

$response = $auth->getAccessToken([CODE]);

Before sending, please replace `[CODE]` in the figure above with the code given from Figure PHP.PAYMENT.8.

Finally, Globe will return an access token you can use to start using the Charge API. **Figure PHP.PAYMENT.10** shows how this response will look like

##### Figure PHP.PAYMENT.10 - Access Token

Array (
"access_token" => "GesiE2YhZlxB9VVMhv-PoI8RwNTsmX0D38g",
"subscriber_number" => "9051234567"
)

##

**Note:** The data in above doesn't actually work. Please don't assume something went wrong
because you tried to use it.

## Charge

To use charge API you will need to send a POST request to the URL given below.

**Request URL**

http://devapi.globelabs.com.ph/payment/v1/transactions/amount

**Parameters**

| Parameters | Definition | Data Type |
|-------|:----------:|:---------:|
| [YOUR_ACCESS_TOKEN] | which contains security information for transacting with a subscriber. Subscriber needs to grant an app first via SMS or Web Form Subscriber Consent Workflow. | String |
| [SUBSCRIBER_NUMBER] | is the MSISDN (mobile number) which you will charge to. Parameter format can be 09xxxxxxxx | String or Integer |
| [AMOUNT] | can be a whole number or decimal | String |
| [REFERENCE_NUMBER] | Is a unique transaction ID with a format of `[SHORT_CODE_WITHOUT_2158]`+`#######` where `#######` is an incremented number beginning from `1000001`. | Integer |


##### Figure PHP.PAYMENT.11 - Sample Charge Request

$charge = $globe->payment(
[YOUR_ACCESS_TOKEN],
[SUBSCRIBER_NUMBER]
);

$response = $charge->charge(
[AMOUNT],
[REFERENCE_NUMBER]
);

##

**Note:** You can get your Short Code value from your Globe App Details in `Figure PHP.PAYMENT.4. You also need to remove the `2158` digit in your short code.

##### Figure PHP.PAYMENT.12 - Sample Charge Response

Array (
"access_token" => "GesiE2YhZlxB9VVMhv-PoI8RwNTsmX0D38g",
"endUserId" => "9171234567",
"amount" => "10",
"referenceCode" => "12341000001",
"success" => true
)

154 changes: 154 additions & 0 deletions Android/docs/sms.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
## Introduction

The Globe Short Message Service(SMS) API lets you develop client applications to communicate with people via text messaging. This document describes how to use the OAUTH/RESTful calling style and client library for Android to access and create Globe message data.

## Getting Started

The first thing we need to do is obtain an **APP ID** and **APP SECRET** from [Globe's Developer Website](http://developer.globelabs.com.ph/users/login). When visiting the link provided you should see a login form similar to *Figure Android.SMS.1*.

##### Figure Android.SMS.1 - Login
![Login Screen](https://raw.github.com/Openovate/rest-docs/master/sms/assets/login.jpg)
====

Currently Globe's RESTful API is in BETA Mode. Ask your local Globe support to gain access to this BETA.

Next, login with your given credentials to get to the APP screen. When you get to the app screen scroll to the bottom right and click the "create" button to create a new app. You should see something familiar to *Figure Android.SMS.2*

##### Figure Android.SMS.2 - Create App Button
![Create App Button](https://raw.github.com/Openovate/rest-docs/master/sms/assets/create.jpg)
====

This will bring you to a form with required information that Globe will need to process your app creation. Fill out this form with the required fields at the very least and press Submit found at the bottom right in *Figure Android.SMS.3*.

##### Figure Android.SMS.3 - Create App Form
![Create App Form](https://raw.github.com/Openovate/rest-docs/master/sms/assets/form.jpg)
====

**Important:** It's important that the Redirect URI and the Notify URI are using actual
URLs as in http://www.example.com/callback. Globe will call these URLs as described in the field.

From here you should be returned to the APP Detail Page in *Figure Android.SMS.4*. The important thing here is the **APP ID** and **APP SECRET**. These will be the information that you will need to manually set in the configurations when writing your application.

##### Figure Android.SMS.4 - App Details
![Create App Form](https://raw.github.com/Openovate/rest-docs/master/sms/assets/detail.jpg)

**Note:** The data in this screen doesn't actually work. Please don't assume something went
wrong because you tried to use it.

## How to Include

First thing before you do any calls for Globe API using Android wrapper class is to include the base class called GlobeApi.

##### Figure Android.SMS.5 - Include Base Class
![Import](https://raw.github.com/Openovate/rest-docs/master/sms/assets/figure1.png)
Import the android project

![Use as library](https://raw.github.com/Openovate/rest-docs/master/sms/assets/figure2.png)
Use the globe api project as a library to your android project

GlobeApi globe = new GlobeApi();

#####

## Authentication

Once we obtain the **APP ID** and **APP SECRET** we can begin to understand how the authentication works. Globe uses [OAUTH2](https://developers.google.com/accounts/docs/OAuth2), a common Android.SMScol to authenticate developers to use API Android.SMScols. To begin the authentication process you must redirect the user to a formatted URL using your **APP ID** and **APP SECRET** as in *Figure Android.SMS.6*.

##### Figure Android.SMS.6 - Invoke a Redirection

Now, initialize the `Auth` class inside GlobeApi and get the login URL using the `getLoginUrl` method.

Auth oauth = globe.auth("[KEY]", "[SECRET");
Strnig loginUrl = oauth.getLoginUrl();

Before invoking your redirect, please replace `[YOUR APP ID]` and `[YOUR APP SECRET]` in the figure above with your actual **APP ID** and **APP SECRET**. Based on what you inputed as your **Redirect URI** in your app details. Globe will authenticate permissions first with the user which should look like *Figure Android.SMS.7a* and *Figure Android.SMS.7b*.

##### Figure Android.SMS.7a - User Flow
![User Flow](https://raw.github.com/Openovate/rest-docs/master/sms/assets/user.jpg)
====
##### Figure Android.SMS.7b - Authorize
![Authorize](https://raw.github.com/Openovate/rest-docs/master/sms/assets/user.jpg)
====

Once the user gives permission, Globe will redirect the user to your Redirect URI with a `code` parameter appended to the end of it. This is how we recieve the code to continue the authentication process. *Figure Android.SMS.8* shows how this redirect will look like given that we set our redirect URI to `http://www.example.com/callback` in our app create form in *Figure Android.SMS.3*.

**Important:** It is also possible that a user can give permissions to your app using just their
phone via SMS. Globe will call (not a phone call) your redirect URI with `access_token` and
`subscriber_number` appended to the end of it. From here you can process this request and
ignore the rest of the authentication process below.

##### Figure Android.SMS.8 - Redirected URI Sample

http://www.example.com/callback?code=12345

`12345` in the URL figure above is what we need in order to get a more long lasting token for your app to use when making API calls. Everytime you make this call the `code` returned will be unique, so you should not hard code the `code` value in your application. The final step in the authentication process is about exchanging your `code` with a more permanent access token. We need to send Globe one final request shown in *Figure Android.SMS.9*

##### Figure Android.SMS.9 - Get the Access Token

Using the `Auth` object we initialized in **Figure Android.SMS.6**, we can get the access token using the script below.

oauth.getAccessToken([CODE], new PostRequestHandler() {
@Override
public void postProcess(String string) {
//<string> is a json string containing the response of the server.
Log.d("TEST ACCESS", string);
}
});

Before sending, please replace `[CODE]` in the figure above with the code given from *Figure Android.SMS.8*.

Finally, Globe will return an access token you can use to start using the SMS API. **Figure Android.SMS.10** shows how this response will look like

##### Figure Android.SMS.10 - Access Token via JSON

{
"access_token": "GesiE2YhZlxB9VVMhv-PoI8RwNTsmX0D38g",
"subscriber_number": "9051234567"'
}

##

**Note:** The data in above doesn't actually work. Please don't assume something went wrong
because you tried to use it.

## Sending

##### Figure Android.SMS.11 - Sample Send Message Request

First we need to initialize the `GlobeApi` class and then use that object to send SMS.

GlobeApi globe = new GlobeApi();
Sms sms = globe.sms([SHORT_CODE]);
sms.sendMessage([access_token], [number], [message], new PostRequestHandler() {
@Override
public void postProcess(String string) {
//<string> is a json string containing the response of the server.
Log.d("TEST ACCESS", string);
}
});

#####

**Note:** You can get your Short Code value from your Globe App Details in `Figure Android.SMS.4. You also need to remove the `2158` digit in your short code.

##### Figure Android.SMS.12 - Sample Send Message Response

{
"outboundSMSMessageRequest": {
"address": "09171234567",
"deliveryInfoList": {
"deliveryInfo": [],
"resourceURL": null
},
"senderAddress": "1234",
"outboundSMSTextMessage": {
"message": "hello"
},
"reciptRequest": {
"notifyURL": null,
"callbackData": null,
"senderName": null,
"resourceURL": null
}
}
}
Binary file added Android/lib/GlobeApiWrapper.zip
Binary file not shown.
35 changes: 35 additions & 0 deletions Android/src/com/globelabs/api/Auth.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.globelabs.api;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

public class Auth extends GlobeApi {
public static final String LOGIN_URL = "http://%s/dialog/oauth";
public static final String AUTH_URL = "http://%s/oauth/access_token";

protected String key;
protected String secret;

public Auth(String key, String secret) {
this.key = key;
this.secret = secret;
}

public String getLoginUrl() {
return String.format(Auth.LOGIN_URL, GlobeApi.AUTH_POINT)+"?app_id="+this.key;
}

public void getAccessToken(String code, PostRequestHandler handler) {
try {
String key = URLEncoder.encode(this.key, "utf-8");
String secret = URLEncoder.encode(this.secret, "utf-8");
String codeEncode = URLEncoder.encode(code, "utf-8");
String url = String.format(Auth.AUTH_URL, GlobeApi.AUTH_POINT)+"?app_id="+key+"&app_secret="+secret+"&code="+codeEncode;
this.__curlPost(url, null, handler);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
}
Loading