graham-instagram 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e37473f7a6e12ae9dae0f4cdddb00e2fbd38e929
4
+ data.tar.gz: 87ab44070e5284a8c199c3541735422ee7abda21
5
+ SHA512:
6
+ metadata.gz: caff574f5afb8f279d76aa53501092388f5db7e5ec56d8d456530239e2f9e42d5c9173b9484c9e76031f3e3d77c78c190df84e15a3ec153ac21f0e03ad4b37ff
7
+ data.tar.gz: 728549bffdb2b02f8a8e209534965a110b8bc04d4df1db5906d04b8463a1c0ee7ee2f0c21562ab645e80d7fae0c351206fa7a455657a9e90514ef010e2b03dfc
@@ -0,0 +1,41 @@
1
+ ### https://raw.github.com/github/gitignore/fceac113a3a20e00718d6317e468eec27f6e2d99/ruby.gitignore
2
+
3
+ *.gem
4
+ *.rbc
5
+ /.config
6
+ /coverage/
7
+ /InstalledFiles
8
+ /pkg/
9
+ /spec/reports/
10
+ /spec/examples.txt
11
+ /test/tmp/
12
+ /test/version_tmp/
13
+ /tmp/
14
+
15
+ ## Specific to RubyMotion:
16
+ .dat*
17
+ .repl_history
18
+ build/
19
+
20
+ ## Documentation cache and generated files:
21
+ /.yardoc/
22
+ /_yardoc/
23
+ /doc/
24
+ /rdoc/
25
+
26
+ ## Environment normalization:
27
+ /.bundle/
28
+ /vendor/bundle
29
+ /lib/bundler/man/
30
+
31
+ # for a library or gem, you might want to ignore these files since the code is
32
+ # intended to run in multiple environments; otherwise, check them in:
33
+ # Gemfile.lock
34
+ # .ruby-version
35
+ # .ruby-gemset
36
+
37
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
38
+ .rvmrc
39
+
40
+
41
+ .env
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.12.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in graham.gemspec
4
+ gemspec
@@ -0,0 +1,44 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ graham-instagram (0.1.0)
5
+ faraday
6
+ faraday_middleware
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ diff-lcs (1.2.5)
12
+ dotenv (2.1.1)
13
+ faraday (0.9.2)
14
+ multipart-post (>= 1.2, < 3)
15
+ faraday_middleware (0.10.0)
16
+ faraday (>= 0.7.4, < 0.10)
17
+ multipart-post (2.0.0)
18
+ rake (10.5.0)
19
+ rspec (3.4.0)
20
+ rspec-core (~> 3.4.0)
21
+ rspec-expectations (~> 3.4.0)
22
+ rspec-mocks (~> 3.4.0)
23
+ rspec-core (3.4.4)
24
+ rspec-support (~> 3.4.0)
25
+ rspec-expectations (3.4.0)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.4.0)
28
+ rspec-mocks (3.4.1)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.4.0)
31
+ rspec-support (3.4.1)
32
+
33
+ PLATFORMS
34
+ ruby
35
+
36
+ DEPENDENCIES
37
+ bundler (~> 1.12)
38
+ dotenv
39
+ graham-instagram!
40
+ rake (~> 10.0)
41
+ rspec (~> 3.0)
42
+
43
+ BUNDLED WITH
44
+ 1.12.4
@@ -0,0 +1,36 @@
1
+ # Graham
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/graham`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'graham-instagram'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install graham-instagram
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/yuchan/graham-instagram.
36
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "graham"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'graham/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "graham-instagram"
8
+ spec.version = Graham::VERSION
9
+ spec.authors = ["Yusuke Ohashi"]
10
+ spec.email = ["github@junkpiano.me"]
11
+
12
+ spec.summary = %q{Instagram Client for Ruby.}
13
+ spec.description = %q{Instagram Client for Ruby.}
14
+ spec.homepage = "https://github.com/yuchan/graham"
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.12"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "rspec", "~> 3.0"
23
+ spec.add_development_dependency "dotenv"
24
+ spec.add_dependency "faraday"
25
+ spec.add_dependency "faraday_middleware"
26
+ end
@@ -0,0 +1,25 @@
1
+ require "graham/version"
2
+ require "graham/configuration"
3
+ require "graham/api"
4
+
5
+ module Graham
6
+ class << self
7
+ def configure
8
+ @config ||= Configuration.new
9
+ yield(@config) if block_given?
10
+ @config
11
+ end
12
+
13
+ def config
14
+ @config || configure
15
+ end
16
+
17
+ def signin_uri
18
+ @config.signin_uri
19
+ end
20
+ end
21
+
22
+ extend API
23
+ end
24
+
25
+
@@ -0,0 +1,131 @@
1
+ require "graham/api/connection"
2
+ require 'json'
3
+
4
+ module Graham
5
+ module API
6
+ include Connection
7
+
8
+ def get_access_token(code)
9
+ url = '/oauth/access_token'
10
+ res = post(url, {
11
+ client_id: config.client_id,
12
+ client_secret: config.client_secret,
13
+ grant_type: 'authorization_code',
14
+ redirect_uri: config.redirect_uri,
15
+ code: code
16
+ })
17
+
18
+ token = nil
19
+ if res.success?
20
+ body = JSON.parse res.body
21
+ token = body["access_token"]
22
+ config.access_token = token
23
+ end
24
+ yield(token) if block_given?
25
+ token
26
+ end
27
+
28
+ def users(userid)
29
+ url = "/v1/users/#{userid}"
30
+ get(url) do |res, body|
31
+ yield(res, body) if block_given?
32
+ end
33
+ end
34
+
35
+ def users_recent(userid)
36
+ url = "/v1/users/#{userid}/media/recent"
37
+ get(url) do |res, body|
38
+ yield(res, body) if block_given?
39
+ end
40
+ end
41
+
42
+ def users_search(username)
43
+ url = "/v1/users/search"
44
+ get(url, {q: username}) do |res, body|
45
+ yield(res, body) if block_given?
46
+ end
47
+ end
48
+
49
+ def tags_info(tagname)
50
+ url = "/v1/tags/#{tagname}"
51
+ get(url) do |res, body|
52
+ yield(res, body) if block_given?
53
+ end
54
+ end
55
+
56
+ def tags_recent(tagname, count = -1, min_tag_id = -1, max_tag_id = -1)
57
+ url = "/v1/tags/#{tagname}/media/recent"
58
+ options = {}
59
+ options["count"] = count if count >= 0
60
+ options["min_tag_id"] = min_tag_id if min_tag_id >= 0
61
+ options["max_tag_id"] = max_tag_id if max_tag_id >= 0
62
+ get(url, options) do |res, body|
63
+ yield(res, body) if block_given?
64
+ end
65
+ end
66
+
67
+ def tags_search(tagname)
68
+ url = "/v1/tags/search"
69
+ get(url, {q: tagname}) do |res, body|
70
+ yield(res, body) if block_given?
71
+ end
72
+ end
73
+
74
+ def likes(media_id)
75
+ url = "/v1/media/#{media_id}/likes"
76
+ get(url) do |res, body|
77
+ yield(res, body) if block_given?
78
+ end
79
+ end
80
+
81
+ def add_like(media_id)
82
+ url = "/v1/media/#{media_id}/likes"
83
+ post(url) do |res, body|
84
+ yield(res, body) if block_given?
85
+ end
86
+ end
87
+
88
+ def delete_like(media_id, like_id)
89
+ url = "/v1/media/#{media_id}/likes"
90
+ delete(url) do |res, body|
91
+ yield(res, body) if block_given?
92
+ end
93
+ end
94
+
95
+ def comments(media_id)
96
+ url = "/v1/media/#{media_id}/comments"
97
+ get(url) do |res, body|
98
+ yield(res, body) if block_given?
99
+ end
100
+ end
101
+
102
+ def add_comment(media_id, comment_text)
103
+ url = "/v1/media/#{media_id}/comments"
104
+ encoded_text = URI.encode(comment_text)
105
+ post(url, {text: encoded_text}) do |res, body|
106
+ yield(res, body) if block_given?
107
+ end
108
+ end
109
+
110
+ def delete_comment(media_id, comment_id)
111
+ url = "/v1/media/#{media_id}/comments/#{comment_id}"
112
+ delete(url) do |res, body|
113
+ yield(res, body) if block_given?
114
+ end
115
+ end
116
+
117
+ def locations_search_by_fb_place_id(location)
118
+ url = "/v1/locations/search"
119
+ get(url, {facebook_places_id: location}) do |res, body|
120
+ yield(res, body) if block_given?
121
+ end
122
+ end
123
+
124
+ def locations_search_by_lat_lng(lat, lng)
125
+ url = "/v1/locations/search"
126
+ get(url, {lat: lat, lng: lng}) do |res, body|
127
+ yield(res, body) if block_given?
128
+ end
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,45 @@
1
+ require 'json'
2
+
3
+ module Graham
4
+ module API
5
+ module Connection
6
+ def post(url, option = nil)
7
+ options = prepareOption(option)
8
+ res = config.conn.post(url, options)
9
+ body = JSON.parse res.body
10
+ yield(res, body) if block_given?
11
+ res
12
+ end
13
+
14
+ def get(url, option = nil)
15
+ options = prepareOption(option)
16
+ res = config.conn.get(url, options)
17
+ body = JSON.parse res.body
18
+ yield(res, body) if block_given?
19
+ res
20
+ end
21
+
22
+ def delete(url, option = nil)
23
+ options = prepareOption(option)
24
+ res = config.conn.delete(url, options)
25
+ body = JSON.parse res.body
26
+ yield(res, body) if block_given?
27
+ res
28
+ end
29
+
30
+ private
31
+
32
+ def prepareOption(option = nil)
33
+ options = {}
34
+ options["access_token"] = config.access_token if config.access_token
35
+ options["client_id"] = config.client_id unless config.access_token
36
+ unless option.nil?
37
+ option.each do |key, value|
38
+ options[key] = value
39
+ end
40
+ end
41
+ options
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,16 @@
1
+ require 'faraday'
2
+
3
+ module Graham
4
+ # Your code goes here...
5
+ class Configuration
6
+ attr_accessor :client_id, :client_secret, :redirect_uri, :access_token, :conn
7
+
8
+ def initialize
9
+ @conn = Faraday.new "https://api.instagram.com"
10
+ end
11
+
12
+ def signin_uri
13
+ "https://api.instagram.com/oauth/authorize/?client_id=" + @client_id + "&redirect_uri=" + @redirect_uri + "&response_type=code" + "&scope=" + "basic+public_content+comments+relationships+likes+follower_list"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module Graham
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: graham-instagram
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yusuke Ohashi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-06-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: dotenv
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: faraday
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: faraday_middleware
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Instagram Client for Ruby.
98
+ email:
99
+ - github@junkpiano.me
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - Gemfile.lock
109
+ - README.md
110
+ - Rakefile
111
+ - bin/console
112
+ - bin/setup
113
+ - graham.gemspec
114
+ - lib/graham.rb
115
+ - lib/graham/api.rb
116
+ - lib/graham/api/connection.rb
117
+ - lib/graham/configuration.rb
118
+ - lib/graham/version.rb
119
+ homepage: https://github.com/yuchan/graham
120
+ licenses: []
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.4.5.1
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Instagram Client for Ruby.
142
+ test_files: []