gistation 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gistation.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Lukas Alexandre
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,85 @@
1
+ # Gistation
2
+
3
+ Gistation provides an API layer for reading an user Github Gists detailed info
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'gistation'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install gistation
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ gist_user = Gistation::GistUser.new 'lukelex' # #<Gistation::GistUser:0x007fe136c615a0 … >
23
+
24
+ gists = gist_user.gists # [#<Gistation::Gist:0x007fedac1ef478 … >, #<Gistation::Gist:0x007fedac1eef28 … >]
25
+
26
+ files = gists.files # [#<Gistation::GistFile:0x007f863cc12ef0 … >, #<Gistation::GistFile:0x007f863bb17ar3 … >]
27
+
28
+ files.first.content
29
+
30
+ =begin
31
+ alias g='git'
32
+ compdef g=git
33
+ alias gs='git status'
34
+ compdef _git gst=git-status
35
+ alias gpl='git pull'
36
+ ...
37
+ =end
38
+ ```
39
+
40
+ ## Avaiable Properties
41
+ ### GistUser
42
+
43
+ * id
44
+ * login
45
+ * email
46
+ * type
47
+ * company
48
+ * public_gists
49
+ * updated_at
50
+ * followers
51
+ * following
52
+ * blog
53
+ * hireable
54
+ * public_repos
55
+ * created_at
56
+ * bio
57
+ * name
58
+ * location
59
+ * gravatar_id
60
+
61
+ ### Gist
62
+
63
+ * name
64
+ * type
65
+ * filename
66
+ * size
67
+ * raw_url
68
+ * language
69
+
70
+ ###GistFile
71
+
72
+ * filename
73
+ * type
74
+ * size
75
+ * raw_url
76
+ * language
77
+ * content
78
+
79
+ ## Contributing
80
+
81
+ 1. Fork it
82
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
83
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
84
+ 4. Push to the branch (`git push origin my-new-feature`)
85
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require "rake/testtask"
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs.push "lib"
7
+ t.test_files = FileList['test/*_test.rb']
8
+ t.verbose = false
9
+ end
10
+
11
+ desc "Run tests"
12
+ task default: :test
data/gistation.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/gistation/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Lukas Alexandre"]
6
+ gem.email = ["lukeskytm@gmail.com"]
7
+ gem.description = %q{Github Gist read layer}
8
+ gem.summary = %q{Gistation provides an API layer for reading an user Github Gists detailed info}
9
+ gem.homepage = "https://github.com/lukelex/gistation"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "gistation"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Gistation::VERSION
17
+
18
+ gem.add_dependency 'json', '~> 1.7.6'
19
+
20
+ gem.add_development_dependency 'minitest', '~> 4.5.0'
21
+ gem.add_development_dependency 'fakeweb', '~> 1.3.0'
22
+ end
@@ -0,0 +1,45 @@
1
+ require_relative 'gist_file'
2
+
3
+ class Gistation::Gist
4
+ FIELDS = [
5
+ :description, :forks_url, :updated_at,
6
+ :url, :html_url, :git_pull_url,
7
+ :public, :comments_url, :git_push_url,
8
+ :comments, :created_at, :id
9
+ ]
10
+
11
+ attr_accessor *FIELDS
12
+
13
+ attr
14
+
15
+ def initialize(params={})
16
+ params.each do |key, value|
17
+ if FIELDS.include? key
18
+ self.send "#{key}=", value
19
+ end
20
+ end
21
+
22
+ @raw_files = params['files']
23
+ end
24
+
25
+ def self.gists_for(user)
26
+ self.request_user_gists_info user
27
+ end
28
+
29
+ def files
30
+ @files ||= Gistation::GistFile.from_hash @raw_files
31
+ end
32
+
33
+ protected
34
+ def self.request_user_gists_info(user)
35
+ uri = URI("https://api.github.com/users/#{user.login}/gists")
36
+
37
+ Gistation.request_to_gist uri do |response|
38
+ gists = []
39
+ response.each do |gist_info|
40
+ gists << Gistation::Gist.new(gist_info)
41
+ end
42
+ gists
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,26 @@
1
+ class Gistation::GistFile
2
+ FIELDS = [
3
+ :filename, :type, :language,
4
+ :size, :raw_url
5
+ ]
6
+
7
+ attr_accessor *FIELDS
8
+
9
+ def initialize(params={})
10
+ params.values.first.each do |key, value|
11
+ if FIELDS.include? key.to_sym
12
+ instance_variable_set "@#{key}", value
13
+ end
14
+ end
15
+ end
16
+
17
+ def self.from_hash(raw_files)
18
+ raw_files.map do |key, value|
19
+ new raw_files
20
+ end
21
+ end
22
+
23
+ def content
24
+ @content ||= Gistation.request_to_gist URI(self.raw_url)
25
+ end
26
+ end
@@ -0,0 +1,34 @@
1
+ require 'gistation/gist'
2
+
3
+ class Gistation::GistUser
4
+ API_URL = 'https://api.github.com/users/'
5
+
6
+ attr_reader :login
7
+
8
+ def initialize(user)
9
+ @login = user
10
+ self.request_user_info
11
+ end
12
+
13
+ def gists
14
+ @gists ||= Gistation::Gist.gists_for self
15
+ end
16
+
17
+ protected
18
+ def request_user_info
19
+ uri = URI(API_URL + self.login)
20
+
21
+ Gistation.request_to_gist uri do |response|
22
+ self.fill_user_object response
23
+ end
24
+ end
25
+
26
+ def fill_user_object(user_info)
27
+ user_info.each do |key, value|
28
+ unless value =~ /^http/
29
+ instance_variable_set "@#{key}".to_sym, value
30
+ self.class.send :attr_reader, key
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module Gistation
2
+ VERSION = "1.0.0"
3
+ end
data/lib/gistation.rb ADDED
@@ -0,0 +1,21 @@
1
+ require 'net/http'
2
+ require 'json'
3
+
4
+ require 'gistation/version'
5
+
6
+ require 'gistation/gist_user'
7
+
8
+ module Gistation
9
+ def self.request_to_gist(uri)
10
+ http = Net::HTTP.new(uri.host, uri.port)
11
+ http.use_ssl = true if uri.scheme == 'https'
12
+
13
+ response = http.start do |http|
14
+ http.request Net::HTTP::Get.new(uri.request_uri)
15
+ end
16
+
17
+ return nil unless response.is_a?(Net::HTTPSuccess)
18
+ return response.body unless block_given?
19
+ yield JSON.parse(response.body)
20
+ end
21
+ end
@@ -0,0 +1,22 @@
1
+ require 'fakeweb'
2
+
3
+ module AuxMethods
4
+ BASE_PATH = File.expand_path("../fixtures", __FILE__)
5
+
6
+ def fetch_fixture_path(path)
7
+ File.join(BASE_PATH, path)
8
+ end
9
+
10
+ def fake_get_url(uri, response, params={})
11
+ uri += with_params(uri, params) unless params.empty?
12
+ FakeWeb.register_uri(:get, uri, :body => response)
13
+ end
14
+
15
+ def fake_put_url(uri, response)
16
+ FakeWeb.register_uri(:put, uri, :body => response)
17
+ end
18
+
19
+ def with_params(url, params)
20
+ url.request_uri + "?" + params.map {|k,v| CGI.escape(k.to_s)+'='+CGI.escape(v.to_s) }.join("&")
21
+ end
22
+ end
@@ -0,0 +1,92 @@
1
+ # Aliases
2
+ # simple stuff
3
+ alias g='git'
4
+ compdef g=git
5
+ alias gs='git status'
6
+ compdef _git gst=git-status
7
+ alias gpl='git pull'
8
+ compdef _git gl=git-pull
9
+ alias gplr='git pull --rebase'
10
+ compdef _git gup=git-fetch
11
+ alias gps='git push'
12
+ compdef _git gp=git-push
13
+ alias gd='git diff'
14
+ gdv() { git diff -w "$@" | view - }
15
+ compdef _git gdv=git-diff
16
+ alias gcm='git commit -v'
17
+ compdef _git gc=git-commit
18
+ alias gcma='git commit -v -a'
19
+ compdef _git gca=git-commit
20
+ alias gc='git checkout'
21
+ compdef _git gco=git-checkout
22
+ alias gcam='git commit -m'
23
+ alias gal='git add .'
24
+
25
+ # fancy stuff
26
+ alias gr='git remote'
27
+ compdef _git gr=git-remote
28
+ alias grv='git remote -v'
29
+ compdef _git grv=git-remote
30
+ alias grmv='git remote rename'
31
+ compdef _git grmv=git-remote
32
+ alias grrm='git remote remove'
33
+ compdef _git grrm=git-remote
34
+ alias grset='git remote set-url'
35
+ compdef _git grset=git-remote
36
+ alias grup='git remote update'
37
+ compdef _git grset=git-remote
38
+ alias gb='git branch'
39
+ compdef _git gb=git-branch
40
+ alias gba='git branch -a'
41
+ compdef _git gba=git-branch
42
+ alias gcount='git shortlog -sn'
43
+ compdef gcount=git
44
+ alias gcfl='git config --list'
45
+ alias gcp='git cherry-pick'
46
+ compdef _git gcp=git-cherry-pick
47
+ alias glg='git log --stat --max-count=5'
48
+ compdef _git glg=git-log
49
+ alias glgg='git log --graph --max-count=5'
50
+ compdef _git glgg=git-log
51
+ alias glgga='git log --graph --decorate --all'
52
+ compdef _git glgga=git-log
53
+ alias gss='git status -s'
54
+ compdef _git gss=git-status
55
+ alias ga='git add'
56
+ compdef _git ga=git-add
57
+ alias gm='git merge'
58
+ compdef _git gm=git-merge
59
+ alias grh='git reset HEAD'
60
+ alias grhh='git reset HEAD --hard'
61
+ alias gwc='git whatchanged -p --abbrev-commit --pretty=medium'
62
+ alias gf='git ls-files | grep'
63
+ alias gpoat='git push origin --all && git push origin --tags'
64
+
65
+ # Will cd into the top of the current repository
66
+ # or submodule.
67
+ alias grt='cd $(git rev-parse --show-toplevel || echo ".")'
68
+
69
+ #
70
+ # Will return the current branch name
71
+ # Usage example: git pull origin $(current_branch)
72
+ #
73
+ function current_branch() {
74
+ ref=$(git symbolic-ref HEAD 2> /dev/null) || \
75
+ ref=$(git rev-parse --short HEAD 2> /dev/null) || return
76
+ echo ${ref#refs/heads/}
77
+ }
78
+
79
+ function current_repository() {
80
+ ref=$(git symbolic-ref HEAD 2> /dev/null) || \
81
+ ref=$(git rev-parse --short HEAD 2> /dev/null) || return
82
+ echo $(git remote -v | cut -d':' -f 2)
83
+ }
84
+
85
+ # these aliases take advantage of the previous function
86
+ alias ggpull='git pull origin $(current_branch)'
87
+ compdef ggpull=git
88
+ alias ggpush='git push origin $(current_branch)'
89
+ compdef ggpush=git
90
+ alias ggpnp='git pull origin $(current_branch) && git push origin $(current_branch)'
91
+ compdef ggpnp=git
92
+ alias gplrb='git pull --rebase origin $(current_branch)'
@@ -0,0 +1,31 @@
1
+ {
2
+ "email": "lukasalexandre@me.com",
3
+ "type": "User",
4
+ "gists_url": "https://api.github.com/users/lukelex/gists{/gist_id}",
5
+ "url": "https://api.github.com/users/lukelex",
6
+ "received_events_url": "https://api.github.com/users/lukelex/received_events",
7
+ "company": "CodeLogic",
8
+ "login": "lukelex",
9
+ "public_gists": 19,
10
+ "updated_at": "2013-01-27T19:05:46Z",
11
+ "organizations_url": "https://api.github.com/users/lukelex/orgs",
12
+ "followers": 10,
13
+ "following": 13,
14
+ "blog": "www.codelogic.me",
15
+ "hireable": true,
16
+ "public_repos": 20,
17
+ "starred_url": "https://api.github.com/users/lukelex/starred{/owner}{/repo}",
18
+ "created_at": "2011-06-10T19:34:46Z",
19
+ "bio": "Web and mobile developer",
20
+ "name": "Lukas Alexandre",
21
+ "location": "Recife - PE",
22
+ "repos_url": "https://api.github.com/users/lukelex/repos",
23
+ "followers_url": "https://api.github.com/users/lukelex/followers",
24
+ "following_url": "https://api.github.com/users/lukelex/following",
25
+ "gravatar_id": "2d24a9678f3ebb040379dd6597adce7f",
26
+ "avatar_url": "https://secure.gravatar.com/avatar/2d24a9678f3ebb040379dd6597adce7f?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png",
27
+ "id": 842850,
28
+ "html_url": "https://github.com/lukelex",
29
+ "events_url": "https://api.github.com/users/lukelex/events{/privacy}",
30
+ "subscriptions_url": "https://api.github.com/users/lukelex/subscriptions"
31
+ }
@@ -0,0 +1,248 @@
1
+ [
2
+ {
3
+ "url": "https://api.github.com/gists/4643343",
4
+ "user": {
5
+ "type": "User",
6
+ "gists_url": "https://api.github.com/users/lukelex/gists{/gist_id}",
7
+ "url": "https://api.github.com/users/lukelex",
8
+ "events_url": "https://api.github.com/users/lukelex/events{/privacy}",
9
+ "avatar_url": "https://secure.gravatar.com/avatar/2d24a9678f3ebb040379dd6597adce7f?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png",
10
+ "login": "lukelex",
11
+ "organizations_url": "https://api.github.com/users/lukelex/orgs",
12
+ "starred_url": "https://api.github.com/users/lukelex/starred{/owner}{/repo}",
13
+ "repos_url": "https://api.github.com/users/lukelex/repos",
14
+ "received_events_url": "https://api.github.com/users/lukelex/received_events",
15
+ "followers_url": "https://api.github.com/users/lukelex/followers",
16
+ "following_url": "https://api.github.com/users/lukelex/following",
17
+ "gravatar_id": "2d24a9678f3ebb040379dd6597adce7f",
18
+ "id": 842850,
19
+ "subscriptions_url": "https://api.github.com/users/lukelex/subscriptions"
20
+ },
21
+ "updated_at": "2013-01-27T01:37:13Z",
22
+ "comments": 0,
23
+ "public": true,
24
+ "forks_url": "https://api.github.com/gists/4643343/forks",
25
+ "created_at": "2013-01-26T17:14:19Z",
26
+ "git_pull_url": "https://gist.github.com/4643343.git",
27
+ "html_url": "https://gist.github.com/4643343",
28
+ "commits_url": "https://api.github.com/gists/4643343/commits",
29
+ "comments_url": "https://api.github.com/gists/4643343/comments",
30
+ "description": "Git aliases",
31
+ "git_push_url": "https://gist.github.com/4643343.git",
32
+ "id": "4643343",
33
+ "files": {
34
+ "git.plugin.zsh": {
35
+ "type": "text/plain",
36
+ "filename": "git.plugin.zsh",
37
+ "size": 2649,
38
+ "raw_url": "https://gist.github.com/raw/4643343/f77f1e49e1aece457b0095ac847afc01af2d335d/git.plugin.zsh",
39
+ "language": "Shell"
40
+ }
41
+ }
42
+ },
43
+ {
44
+ "url": "https://api.github.com/gists/4499269",
45
+ "user": {
46
+ "type": "User",
47
+ "gists_url": "https://api.github.com/users/lukelex/gists{/gist_id}",
48
+ "url": "https://api.github.com/users/lukelex",
49
+ "events_url": "https://api.github.com/users/lukelex/events{/privacy}",
50
+ "avatar_url": "https://secure.gravatar.com/avatar/2d24a9678f3ebb040379dd6597adce7f?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png",
51
+ "login": "lukelex",
52
+ "organizations_url": "https://api.github.com/users/lukelex/orgs",
53
+ "starred_url": "https://api.github.com/users/lukelex/starred{/owner}{/repo}",
54
+ "repos_url": "https://api.github.com/users/lukelex/repos",
55
+ "received_events_url": "https://api.github.com/users/lukelex/received_events",
56
+ "followers_url": "https://api.github.com/users/lukelex/followers",
57
+ "following_url": "https://api.github.com/users/lukelex/following",
58
+ "gravatar_id": "2d24a9678f3ebb040379dd6597adce7f",
59
+ "id": 842850,
60
+ "subscriptions_url": "https://api.github.com/users/lukelex/subscriptions"
61
+ },
62
+ "updated_at": "2013-01-10T03:49:01Z",
63
+ "comments": 0,
64
+ "public": true,
65
+ "forks_url": "https://api.github.com/gists/4499269/forks",
66
+ "created_at": "2013-01-10T03:49:00Z",
67
+ "git_pull_url": "https://gist.github.com/4499269.git",
68
+ "html_url": "https://gist.github.com/4499269",
69
+ "commits_url": "https://api.github.com/gists/4499269/commits",
70
+ "comments_url": "https://api.github.com/gists/4499269/comments",
71
+ "description": "Require all ruby files from a directory",
72
+ "git_push_url": "https://gist.github.com/4499269.git",
73
+ "id": "4499269",
74
+ "files": {
75
+ "require_dir": {
76
+ "type": "text/plain",
77
+ "filename": "require_dir",
78
+ "size": 59,
79
+ "raw_url": "https://gist.github.com/raw/4499269/528e16d468cf739497908162995d2d0077410218/require_dir",
80
+ "language": null
81
+ }
82
+ }
83
+ },
84
+ {
85
+ "url": "https://api.github.com/gists/4370359",
86
+ "user": {
87
+ "type": "User",
88
+ "gists_url": "https://api.github.com/users/lukelex/gists{/gist_id}",
89
+ "url": "https://api.github.com/users/lukelex",
90
+ "events_url": "https://api.github.com/users/lukelex/events{/privacy}",
91
+ "avatar_url": "https://secure.gravatar.com/avatar/2d24a9678f3ebb040379dd6597adce7f?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png",
92
+ "login": "lukelex",
93
+ "organizations_url": "https://api.github.com/users/lukelex/orgs",
94
+ "starred_url": "https://api.github.com/users/lukelex/starred{/owner}{/repo}",
95
+ "repos_url": "https://api.github.com/users/lukelex/repos",
96
+ "received_events_url": "https://api.github.com/users/lukelex/received_events",
97
+ "followers_url": "https://api.github.com/users/lukelex/followers",
98
+ "following_url": "https://api.github.com/users/lukelex/following",
99
+ "gravatar_id": "2d24a9678f3ebb040379dd6597adce7f",
100
+ "id": 842850,
101
+ "subscriptions_url": "https://api.github.com/users/lukelex/subscriptions"
102
+ },
103
+ "updated_at": "2012-12-24T18:59:03Z",
104
+ "comments": 0,
105
+ "public": true,
106
+ "forks_url": "https://api.github.com/gists/4370359/forks",
107
+ "created_at": "2012-12-24T18:59:02Z",
108
+ "git_pull_url": "https://gist.github.com/4370359.git",
109
+ "html_url": "https://gist.github.com/4370359",
110
+ "commits_url": "https://api.github.com/gists/4370359/commits",
111
+ "comments_url": "https://api.github.com/gists/4370359/comments",
112
+ "description": "Toggle an attribute",
113
+ "git_push_url": "https://gist.github.com/4370359.git",
114
+ "id": "4370359",
115
+ "files": {
116
+ "toggle_attribute.js": {
117
+ "type": "application/javascript",
118
+ "filename": "toggle_attribute.js",
119
+ "size": 83,
120
+ "raw_url": "https://gist.github.com/raw/4370359/876e05b40f27ceb193c49d3b96cbcfd795536cfa/toggle_attribute.js",
121
+ "language": "JavaScript"
122
+ }
123
+ }
124
+ },
125
+ {
126
+ "url": "https://api.github.com/gists/4369401",
127
+ "user": {
128
+ "type": "User",
129
+ "gists_url": "https://api.github.com/users/lukelex/gists{/gist_id}",
130
+ "url": "https://api.github.com/users/lukelex",
131
+ "events_url": "https://api.github.com/users/lukelex/events{/privacy}",
132
+ "avatar_url": "https://secure.gravatar.com/avatar/2d24a9678f3ebb040379dd6597adce7f?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png",
133
+ "login": "lukelex",
134
+ "organizations_url": "https://api.github.com/users/lukelex/orgs",
135
+ "starred_url": "https://api.github.com/users/lukelex/starred{/owner}{/repo}",
136
+ "repos_url": "https://api.github.com/users/lukelex/repos",
137
+ "received_events_url": "https://api.github.com/users/lukelex/received_events",
138
+ "followers_url": "https://api.github.com/users/lukelex/followers",
139
+ "following_url": "https://api.github.com/users/lukelex/following",
140
+ "gravatar_id": "2d24a9678f3ebb040379dd6597adce7f",
141
+ "id": 842850,
142
+ "subscriptions_url": "https://api.github.com/users/lukelex/subscriptions"
143
+ },
144
+ "updated_at": "2012-12-24T14:17:25Z",
145
+ "comments": 0,
146
+ "public": true,
147
+ "forks_url": "https://api.github.com/gists/4369401/forks",
148
+ "created_at": "2012-12-24T14:17:24Z",
149
+ "git_pull_url": "https://gist.github.com/4369401.git",
150
+ "html_url": "https://gist.github.com/4369401",
151
+ "commits_url": "https://api.github.com/gists/4369401/commits",
152
+ "comments_url": "https://api.github.com/gists/4369401/comments",
153
+ "description": "Installing latest version of MongoDB on ubuntu",
154
+ "git_push_url": "https://gist.github.com/4369401.git",
155
+ "id": "4369401",
156
+ "files": {
157
+ "install.md": {
158
+ "type": "text/plain",
159
+ "filename": "install.md",
160
+ "size": 1916,
161
+ "raw_url": "https://gist.github.com/raw/4369401/d6b77a3ac0f741ad1f2215c3b76690824684b38f/install.md",
162
+ "language": "Markdown"
163
+ }
164
+ }
165
+ },
166
+ {
167
+ "url": "https://api.github.com/gists/4242153",
168
+ "user": {
169
+ "type": "User",
170
+ "gists_url": "https://api.github.com/users/lukelex/gists{/gist_id}",
171
+ "url": "https://api.github.com/users/lukelex",
172
+ "events_url": "https://api.github.com/users/lukelex/events{/privacy}",
173
+ "avatar_url": "https://secure.gravatar.com/avatar/2d24a9678f3ebb040379dd6597adce7f?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png",
174
+ "login": "lukelex",
175
+ "organizations_url": "https://api.github.com/users/lukelex/orgs",
176
+ "starred_url": "https://api.github.com/users/lukelex/starred{/owner}{/repo}",
177
+ "repos_url": "https://api.github.com/users/lukelex/repos",
178
+ "received_events_url": "https://api.github.com/users/lukelex/received_events",
179
+ "followers_url": "https://api.github.com/users/lukelex/followers",
180
+ "following_url": "https://api.github.com/users/lukelex/following",
181
+ "gravatar_id": "2d24a9678f3ebb040379dd6597adce7f",
182
+ "id": 842850,
183
+ "subscriptions_url": "https://api.github.com/users/lukelex/subscriptions"
184
+ },
185
+ "updated_at": "2012-12-08T21:58:20Z",
186
+ "comments": 0,
187
+ "public": true,
188
+ "forks_url": "https://api.github.com/gists/4242153/forks",
189
+ "created_at": "2012-12-08T21:58:20Z",
190
+ "git_pull_url": "https://gist.github.com/4242153.git",
191
+ "html_url": "https://gist.github.com/4242153",
192
+ "commits_url": "https://api.github.com/gists/4242153/commits",
193
+ "comments_url": "https://api.github.com/gists/4242153/comments",
194
+ "description": "Generic table item sorter in coffeescript & jquery",
195
+ "git_push_url": "https://gist.github.com/4242153.git",
196
+ "id": "4242153",
197
+ "files": {
198
+ "sorter.coffee": {
199
+ "type": "text/coffescript",
200
+ "filename": "sorter.coffee",
201
+ "size": 1799,
202
+ "raw_url": "https://gist.github.com/raw/4242153/5f365c79adff88d1bbbe5a3a826188efdf9a8121/sorter.coffee",
203
+ "language": "CoffeeScript"
204
+ }
205
+ }
206
+ },
207
+ {
208
+ "url": "https://api.github.com/gists/3379523",
209
+ "user": {
210
+ "type": "User",
211
+ "gists_url": "https://api.github.com/users/lukelex/gists{/gist_id}",
212
+ "url": "https://api.github.com/users/lukelex",
213
+ "events_url": "https://api.github.com/users/lukelex/events{/privacy}",
214
+ "avatar_url": "https://secure.gravatar.com/avatar/2d24a9678f3ebb040379dd6597adce7f?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png",
215
+ "login": "lukelex",
216
+ "organizations_url": "https://api.github.com/users/lukelex/orgs",
217
+ "starred_url": "https://api.github.com/users/lukelex/starred{/owner}{/repo}",
218
+ "repos_url": "https://api.github.com/users/lukelex/repos",
219
+ "received_events_url": "https://api.github.com/users/lukelex/received_events",
220
+ "followers_url": "https://api.github.com/users/lukelex/followers",
221
+ "following_url": "https://api.github.com/users/lukelex/following",
222
+ "gravatar_id": "2d24a9678f3ebb040379dd6597adce7f",
223
+ "id": 842850,
224
+ "subscriptions_url": "https://api.github.com/users/lukelex/subscriptions"
225
+ },
226
+ "updated_at": "2012-08-17T14:57:53Z",
227
+ "comments": 0,
228
+ "public": true,
229
+ "forks_url": "https://api.github.com/gists/3379523/forks",
230
+ "created_at": "2012-08-17T14:57:53Z",
231
+ "git_pull_url": "https://gist.github.com/3379523.git",
232
+ "html_url": "https://gist.github.com/3379523",
233
+ "commits_url": "https://api.github.com/gists/3379523/commits",
234
+ "comments_url": "https://api.github.com/gists/3379523/comments",
235
+ "description": "Converts brazilian money to american money",
236
+ "git_push_url": "https://gist.github.com/3379523.git",
237
+ "id": "3379523",
238
+ "files": {
239
+ "money2float": {
240
+ "type": "text/plain",
241
+ "filename": "money2float",
242
+ "size": 133,
243
+ "raw_url": "https://gist.github.com/raw/3379523/82ed864cb06dea2a49a2b7184681494bc637b8d9/money2float",
244
+ "language": null
245
+ }
246
+ }
247
+ }
248
+ ]
data/test/gist_test.rb ADDED
@@ -0,0 +1,43 @@
1
+ require_relative 'test_helper'
2
+
3
+ describe Gistation::Gist do
4
+ describe 'Getting gist files' do
5
+ it 'type check' do
6
+ gist.files.first.must_be_instance_of Gistation::GistFile
7
+ end
8
+
9
+ it 'remotely' do
10
+ gist.files.size.must_equal 1
11
+ end
12
+
13
+ # it 'from cache'
14
+ end
15
+
16
+ describe 'cheking properties initalization' do
17
+ it 'filename' do
18
+ gist_file.filename.must_equal 'git.plugin.zsh'
19
+ end
20
+
21
+ it 'type' do
22
+ gist_file.type.must_equal 'text/plain'
23
+ end
24
+
25
+ it 'size' do
26
+ gist_file.size.must_equal 2649
27
+ end
28
+
29
+ it 'language' do
30
+ gist_file.language.must_equal 'Shell'
31
+ end
32
+
33
+ it 'raw_url' do
34
+ gist_file.raw_url.must_equal 'https://gist.github.com/raw/4643343/f77f1e49e1aece457b0095ac847afc01af2d335d/git.plugin.zsh'
35
+ end
36
+ end
37
+
38
+ describe 'getting the file content' do
39
+ it 'remotely' do
40
+ gist_file.content.must_equal gist_file_content
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,21 @@
1
+ require_relative 'test_helper'
2
+
3
+ describe Gistation::GistUser do
4
+ describe 'Getting the user' do
5
+ it 'remotely' do
6
+ gist_user.email.must_equal 'lukasalexandre@me.com'
7
+ end
8
+
9
+ # it 'from cache'
10
+ end
11
+
12
+ describe 'getting its Gists' do
13
+ it 'remotely' do
14
+ gist_user.gists.wont_be_empty
15
+ gist_user.gists.size.must_equal 6
16
+ gist_user.gists.first.must_be_instance_of Gistation::Gist
17
+ end
18
+
19
+ # it ('from cache')
20
+ end
21
+ end
@@ -0,0 +1,28 @@
1
+ require 'minitest/spec'
2
+ require 'minitest/autorun'
3
+ require 'turn'
4
+ require 'gistation'
5
+
6
+ require_relative 'aux_methods'
7
+
8
+ class MiniTest::Spec
9
+ include AuxMethods
10
+
11
+ let (:gist_user) { Gistation::GistUser.new 'lukelex' }
12
+ let (:gist) { gist_user.gists.first }
13
+ let (:gist_file) { gist.files.first }
14
+
15
+ let (:gist_user_response) { fetch_fixture_path('gist_user.json') }
16
+ let (:user_gists_response) { fetch_fixture_path('user_gists.json') }
17
+ let (:gist_file_content_response) { fetch_fixture_path('gist_file_content.txt') }
18
+
19
+ let (:gist_file_content) { File.read gist_file_content_response }
20
+
21
+ before do
22
+ FakeWeb.allow_net_connect = false
23
+
24
+ fake_get_url 'https://api.github.com/users/lukelex', gist_user_response
25
+ fake_get_url 'https://api.github.com/users/lukelex/gists', user_gists_response
26
+ fake_get_url 'https://gist.github.com/raw/4643343/f77f1e49e1aece457b0095ac847afc01af2d335d/git.plugin.zsh', gist_file_content_response
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gistation
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Lukas Alexandre
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: json
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.7.6
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.7.6
30
+ - !ruby/object:Gem::Dependency
31
+ name: minitest
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 4.5.0
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 4.5.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: fakeweb
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 1.3.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.3.0
62
+ description: Github Gist read layer
63
+ email:
64
+ - lukeskytm@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - LICENSE
72
+ - README.md
73
+ - Rakefile
74
+ - gistation.gemspec
75
+ - lib/gistation.rb
76
+ - lib/gistation/gist.rb
77
+ - lib/gistation/gist_file.rb
78
+ - lib/gistation/gist_user.rb
79
+ - lib/gistation/version.rb
80
+ - test/aux_methods.rb
81
+ - test/fixtures/gist_file_content.txt
82
+ - test/fixtures/gist_user.json
83
+ - test/fixtures/user_gists.json
84
+ - test/gist_test.rb
85
+ - test/gist_user_test.rb
86
+ - test/test_helper.rb
87
+ homepage: https://github.com/lukelex/gistation
88
+ licenses: []
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 1.8.25
108
+ signing_key:
109
+ specification_version: 3
110
+ summary: Gistation provides an API layer for reading an user Github Gists detailed
111
+ info
112
+ test_files:
113
+ - test/aux_methods.rb
114
+ - test/fixtures/gist_file_content.txt
115
+ - test/fixtures/gist_user.json
116
+ - test/fixtures/user_gists.json
117
+ - test/gist_test.rb
118
+ - test/gist_user_test.rb
119
+ - test/test_helper.rb