Skip to content

Commit

Permalink
Merge pull request #101 from Fullscreen/revert-app-token-by-request
Browse files Browse the repository at this point in the history
revert 'Use App Access Token generated by GET for all API requests'
  • Loading branch information
kangkyu authored Oct 25, 2017
2 parents f33c682 + 24bc5ba commit 923eb1e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ For more information about changelogs, check
[Keep a Changelog](http://keepachangelog.com) and
[Vandamme](http://tech-angels.github.io/vandamme).

## 0.2.31 - 2017/10/25

* [BUGFIX] Revert the change of version 0.2.29 and do not use request to get app
access token.
* [ENHANCEMENT] Allow funky to scrape view count for more videos, by changing
the way how to scrape.

## 0.2.30 - 2017/10/16

* [BUGFIX] Test should pass when call Page#videos. Partly revert the change
Expand Down
16 changes: 4 additions & 12 deletions lib/funky/connections/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Funky
module Connection
class API < Base
def self.fetch_all(path_query)
uri = URI "https://#{host}/v2.9/#{path_query}&limit=100&access_token=#{app_access_token}"
uri = URI "https://#{host}/v2.9/#{path_query}&limit=100&access_token=#{app_id}%7C#{app_secret}"
fetch_data_with_paging_token(uri)
end

Expand All @@ -24,7 +24,7 @@ def self.fetch_data_with_paging_token(uri)
end

def self.fetch(path_query, is_array: false)
uri = URI "https://#{host}/v2.8/#{path_query}&limit=100&access_token=#{app_access_token}"
uri = URI "https://#{host}/v2.8/#{path_query}&limit=100&access_token=#{app_id}%7C#{app_secret}"
is_array ? fetch_multiple_pages(uri).uniq : json_for(uri)
rescue URI::InvalidURIError
raise Funky::ContentNotFound, "Invalid URL"
Expand Down Expand Up @@ -66,14 +66,14 @@ def self.fetch_multiple_pages(uri)
def self.request(id:, fields:)
uri = URI::HTTPS.build host: host,
path: "/v2.8/#{id}",
query: "access_token=#{app_access_token}&fields=#{fields}"
query: "access_token=#{app_id}%7C#{app_secret}&fields=#{fields}"
response_for(get_http_request(uri), uri)
end

def self.batch_request(ids:, fields:)
uri = URI::HTTPS.build host: host,
path: "/",
query: "include_headers=false&access_token=#{app_access_token}"
query: "include_headers=false&access_token=#{app_id}%7C#{app_secret}"
batch = create_batch_for ids, fields
http_request = post_http_request uri
http_request.set_form_data batch: batch.to_json
Expand All @@ -94,14 +94,6 @@ def self.app_secret
Funky.configuration.app_secret
end

def self.app_access_token
@app_access_token ||= begin
uri = URI::HTTPS.build host: host, path: "/v2.8/oauth/access_token",
query: URI.encode_www_form({client_id: app_id, client_secret: app_secret, grant_type: 'client_credentials'})
Funky::Connection::API.json_for(uri)[:access_token]
end
end

def self.post_http_request(uri)
Net::HTTP::Post.new uri
end
Expand Down
2 changes: 1 addition & 1 deletion lib/funky/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Funky
VERSION = "0.2.30"
VERSION = "0.2.31"
end

0 comments on commit 923eb1e

Please sign in to comment.