Skip to content

Commit 722feda

Browse files
author
Nicholas Cerminara
committed
added bunch of stuff plus demo :github:
1 parent 8e96996 commit 722feda

File tree

216 files changed

+53410
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

216 files changed

+53410
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

.htaccess

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<IfModule mod_rewrite.c>
2+
RewriteEngine On
3+
RewriteBase /
4+
5+
#Removes access to the system folder by users.
6+
#Additionally this will allow you to create a System.php controller,
7+
#previously this would not have been possible.
8+
#'system' can be replaced if you have renamed your system folder.
9+
RewriteCond %{REQUEST_URI} ^system.*
10+
RewriteRule ^(.*)$ /index.php?/$1 [L]
11+
12+
#When your application folder isn't in the system folder
13+
#This snippet prevents user access to the application folder
14+
#Submitted by: Fabdrol
15+
#Rename 'application' to your applications folder name.
16+
RewriteCond %{REQUEST_URI} ^application.*
17+
RewriteRule ^(.*)$ /index.php?/$1 [L]
18+
19+
#Checks to see if the user is attempting to access a valid file,
20+
#such as an image or css document, if this isn't true it sends the
21+
#request to index.php
22+
RewriteCond %{REQUEST_FILENAME} !-f
23+
RewriteCond %{REQUEST_FILENAME} !-d
24+
RewriteRule ^(.*)$ index.php?/$1 [L]
25+
</IfModule>
26+
27+
<IfModule !mod_rewrite.c>
28+
# If we don't have mod_rewrite installed, all 404's
29+
# can be sent to index.php, and everything works as normal.
30+
# Submitted by: ElliotHaughin
31+
32+
ErrorDocument 404 /index.php
33+
</IfModule>

README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,70 @@ Github-API-Library-For-CodeIgniter
22
===================================
33

44
Simple Github library for CodeIgniter. Supports GitHub OAuth API and all the other cool little functions and calls they have.
5+
6+
## What is this?
7+
8+
It's an out of the box starter for using OAuth and GitHub. It uses the latest version of Codeigniter and has a running demo so all you have to do is set your config keys and you're done. It's one of my last CodeIgniter projects that I want to open-source before embracing the Laravel world entirely.
9+
10+
## Are all these files required?
11+
12+
No.There's a lot of stuff that this comes with. You don't need most of these files to get started. For example, I use our [Stencil Codeigniter Template Library](http://github.com/scotch-io/stencil) to do the templating. You don't have to do that.
13+
14+
### Requried Files:
15+
16+
- /application/config/github.php
17+
- /applicaiton/library/Github.php
18+
- /application/controllers/authorize.php (not technically necessary, but might as well use it since it's already built for you)
19+
20+
21+
## Basics of how everything works
22+
23+
First, autoload the config and the library, then set your config settings.
24+
25+
### Determine if a User is Logged In
26+
27+
This library determines if you are logged in if you have a GitHub Access Token or not. To see if you are logged in or not just call the function:
28+
29+
> `$this->github->get_access_token()`
30+
31+
This will return FALSE if the user is not logged in. If the user isn't logged in, you'll need to log them in!
32+
33+
34+
### Log in a user
35+
36+
You need to send them to the GitHub login URL. You can do this by having them click there via an `<a>` tag or just by redirecting them. This is how you get the login URL:
37+
38+
> `$this->github->get_login_url()`
39+
40+
That's it! Make sure that wherever your redirect uri config option is set has this function in it receiving it:
41+
42+
> `$this->github->authorize()`
43+
44+
This function pretty much does everything for you -- checking all sorts of OAuth verification checks. If the function returns FALSE, the login failed. You get any error messages like this:
45+
46+
> `$this->github->get_error()`
47+
48+
See the `authorize` controller to understand better how it works. Invoking this method will also work for any other times an error needs to be caught.
49+
50+
### Getting Data -- curl(), the super REST function
51+
52+
This function is intended to make all GitHub REST API calls. This is how it is broken down:
53+
54+
> `public function curl($uri, $verb = 'GET', $body = array(), $headers = FALSE)`
55+
56+
So whenever you call this function, it will automatically build a URL with the access token based on the arguments you submit.
57+
58+
For example, if you want to get list your gists, it will look like this:
59+
60+
> `$this->github->curl('gists').
61+
62+
Simple. if you need to do something more complicated it could look like this:
63+
64+
> '$this->github->curl('gists/'.$id, 'PATCH', $body);'
65+
66+
It can even return HTTP Codes (perfect for REST). It would look something like this:
67+
68+
> $this->github->curl('gists/'.$id.'/star', 'GET', '', TRUE);
69+
70+
## Notes / To-Dos
71+
- Throw Errors for try/catch versus returning FALSE all the time

application/.htaccess

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Deny from all

application/cache/.htaccess

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
deny from all

application/cache/index.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<html>
2+
<head>
3+
<title>403 Forbidden</title>
4+
</head>
5+
<body>
6+
7+
<p>Directory access is forbidden.</p>
8+
9+
</body>
10+
</html>

application/config/autoload.php

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2+
/*
3+
| -------------------------------------------------------------------
4+
| AUTO-LOADER
5+
| -------------------------------------------------------------------
6+
| This file specifies which systems should be loaded by default.
7+
|
8+
| In order to keep the framework as light-weight as possible only the
9+
| absolute minimal resources are loaded by default. For example,
10+
| the database is not connected to automatically since no assumption
11+
| is made regarding whether you intend to use it. This file lets
12+
| you globally define which systems you would like loaded with every
13+
| request.
14+
|
15+
| -------------------------------------------------------------------
16+
| Instructions
17+
| -------------------------------------------------------------------
18+
|
19+
| These are the things you can load automatically:
20+
|
21+
| 1. Packages
22+
| 2. Libraries
23+
| 3. Helper files
24+
| 4. Custom config files
25+
| 5. Language files
26+
| 6. Models
27+
|
28+
*/
29+
30+
/*
31+
| -------------------------------------------------------------------
32+
| Auto-load Packges
33+
| -------------------------------------------------------------------
34+
| Prototype:
35+
|
36+
| $autoload['packages'] = array(APPPATH.'third_party', '/usr/local/shared');
37+
|
38+
*/
39+
40+
$autoload['packages'] = array();
41+
42+
43+
/*
44+
| -------------------------------------------------------------------
45+
| Auto-load Libraries
46+
| -------------------------------------------------------------------
47+
| These are the classes located in the system/libraries folder
48+
| or in your application/libraries folder.
49+
|
50+
| Prototype:
51+
|
52+
| $autoload['libraries'] = array('database', 'session', 'xmlrpc');
53+
*/
54+
55+
$autoload['libraries'] = array('stencil', 'slices', 'form_validation', 'session', 'github');
56+
57+
58+
/*
59+
| -------------------------------------------------------------------
60+
| Auto-load Helper Files
61+
| -------------------------------------------------------------------
62+
| Prototype:
63+
|
64+
| $autoload['helper'] = array('url', 'file');
65+
*/
66+
67+
$autoload['helper'] = array('stencil', 'html', 'form', 'url', 'alert');
68+
69+
70+
/*
71+
| -------------------------------------------------------------------
72+
| Auto-load Config files
73+
| -------------------------------------------------------------------
74+
| Prototype:
75+
|
76+
| $autoload['config'] = array('config1', 'config2');
77+
|
78+
| NOTE: This item is intended for use ONLY if you have created custom
79+
| config files. Otherwise, leave it blank.
80+
|
81+
*/
82+
83+
$autoload['config'] = array('stencil', 'github');
84+
85+
86+
/*
87+
| -------------------------------------------------------------------
88+
| Auto-load Language files
89+
| -------------------------------------------------------------------
90+
| Prototype:
91+
|
92+
| $autoload['language'] = array('lang1', 'lang2');
93+
|
94+
| NOTE: Do not include the "_lang" part of your file. For example
95+
| "codeigniter_lang.php" would be referenced as array('codeigniter');
96+
|
97+
*/
98+
99+
$autoload['language'] = array();
100+
101+
102+
/*
103+
| -------------------------------------------------------------------
104+
| Auto-load Models
105+
| -------------------------------------------------------------------
106+
| Prototype:
107+
|
108+
| $autoload['model'] = array('model1', 'model2');
109+
|
110+
*/
111+
112+
$autoload['model'] = array();
113+
114+
115+
/* End of file autoload.php */
116+
/* Location: ./application/config/autoload.php */

0 commit comments

Comments
 (0)