vinery 0.0.1

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: 63d4bddfaed7dee2966e0b13304ee9744ea35d37
4
+ data.tar.gz: 02fd83fdd59a6bdca36ed5b36e65a36368641e1b
5
+ SHA512:
6
+ metadata.gz: 36e734bd48ce8528616e66b6c93629cf653946e0f6332b0740aa6593e885cb971790a19ff8c2e6eecb7535350bc75b3ba1178bf14473fa9a6fc36a10ecf5acea
7
+ data.tar.gz: 833eb18d671fbe27b4af62417ec27d935f2eca533ef758eafb41ca4affbdec0ba7cc5fc9ba7114415479472de4254e359a43c9cf19e4a30e8481cbffae29912a
@@ -0,0 +1,18 @@
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
18
+ .env
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vinery.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Jake Bellacera
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.
@@ -0,0 +1,46 @@
1
+ # Vinery
2
+
3
+ A Ruby interface for [Vine](http://vine.co).
4
+
5
+ ***
6
+
7
+ **NOTE:** Vinery currently only has one API method at the moment: `tagged`. This interface is very incomplete right now, so please contribute!
8
+
9
+ ***
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem 'vinery'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install vinery
24
+
25
+ ## Usage
26
+
27
+ Vine's API requires _all_ requests to be authenticated (via a session cookie) with a valid Vine username and password. Vinery will authenticate you upon initialization.
28
+
29
+ To begin, `require` Vinery in your ruby script and then create a new instance of `Vinery::API` by passing your Vine username and password as parameters.
30
+
31
+ ```ruby
32
+ require 'vinery'
33
+ vinery = Vinery::API.new(vine_username,vine_password)
34
+ ```
35
+
36
+ If Vine rejects your credentials, Vinery will raise `InvalidCredentialsError`. If no errors occur, then you have successfully authenticated with Vine and you're ready to go!
37
+
38
+ To learn more about how to work with `Vinery::API`, [browse the source code](lib/vinery/api.rb).
39
+
40
+ ## Contributing
41
+
42
+ 1. Fork it
43
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
44
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
45
+ 4. Push to the branch (`git push origin my-new-feature`)
46
+ 5. Create new Pull Request
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << "lib"
6
+ t.libs << "test"
7
+ t.pattern = "test/*_test.rb"
8
+ end
@@ -0,0 +1,5 @@
1
+ require "json"
2
+ require "vinery/version"
3
+ require "vinery/record"
4
+ require "vinery/collection"
5
+ require "vinery/api"
@@ -0,0 +1,115 @@
1
+ require "httparty"
2
+ require "vinery/errors/invalid_credentials"
3
+
4
+ module Vinery
5
+ # Public: The unofficial interface for the Vine API. Vine requires all
6
+ # requests to be authenticated when accessing the API.
7
+ #
8
+ # Examples
9
+ #
10
+ # vinery = Vinery::API.new("username", "password")
11
+ # funny_vines = vinery.tagged("funny")
12
+ class API
13
+ include HTTParty
14
+ base_uri "https://api.vineapp.com"
15
+
16
+ # Public: Initializes a new Vine API instance.
17
+ #
18
+ # username - The String Vine username.
19
+ # password - The String Vine password.
20
+ #
21
+ # Examples
22
+ #
23
+ # vinery = Vinery::API.new("username", "password")
24
+ #
25
+ # Returns the new Vine instance.
26
+ def initialize(username, password)
27
+ login(username, password)
28
+ end
29
+
30
+ # Public: fetches a list of Vines that are tagged with a certain tag.
31
+ #
32
+ # tag - The String tag to search for.
33
+ # query - The Hash options used to refine the selection (default: {}).
34
+ # :page - The Integer page number to paginate results (default: 1).
35
+ # :size - The Integer number of results to display (default: 20).
36
+ #
37
+ # Examples
38
+ #
39
+ # vinery.tagged("funny")
40
+ #
41
+ # vinery.tagged("funny", { page: 2, size: 10 })
42
+ #
43
+ # Returns a Hash of Vines.
44
+ def tagged(tag, query = {})
45
+ query = {
46
+ page: 1,
47
+ size: 20
48
+ }.merge!(query)
49
+
50
+ Collection.new(get_parsed("/timelines/tags/#{tag}", query)["records"].map { |r| Record.new(r) })
51
+ end
52
+
53
+ private
54
+
55
+ # Private: authenticates a Vine user with the Vine API. This method only needs
56
+ # to be ran once per Vine instance.
57
+ #
58
+ # username - The String Vine username.
59
+ # password - The String Vine password.
60
+ #
61
+ # Returns nothing.
62
+ def login(username, password)
63
+ response = self.class.post("/users/authenticate", {
64
+ body: {
65
+ username: username,
66
+ password: password
67
+ }
68
+ })
69
+
70
+ body = parse_json(response.body)
71
+
72
+ raise Vinery::InvalidCredentialsError unless body["success"]
73
+
74
+ @auth = {
75
+ user_id: body["data"]["userId"],
76
+ key: body["data"]["key"]
77
+ }
78
+ end
79
+
80
+ # Private: performs an HTTP GET request with required headers.
81
+ #
82
+ # url - The String URL that we would GET. The URL should be relative to the
83
+ # Vine API's domain.
84
+ # query - The Hash of query key/value pairs (default: {}).
85
+ # headers - The Hash of additional HTTP request headers (default: {}).
86
+ #
87
+ # Returns an instance of HTTParty::Response.
88
+ def get(url, query = {}, headers = {})
89
+ headers.merge!({
90
+ "User-Agent" => "com.vine.iphone/1.0.3 (unknown, iPhone OS 6.0.1, iPhone, Scale/2.000000)",
91
+ "Accept-Language" => "en, sv, fr, de, ja, nl, it, es, pt, pt-PT, da, fi, nb, ko, zh-Hans, zh-Hant, ru, pl, tr, uk, ar, hr, cs, el, he, ro, sk, th, id, ms, en-GB, ca, hu, vi, en-us;q=0.8",
92
+ "vine-session-id" => @auth[:key]
93
+ })
94
+
95
+ self.class.get(url, { query: query, headers: headers })
96
+ end
97
+
98
+ # Private: perfoms the get method and parses the response.
99
+ #
100
+ # Returns a Hash of the HTTP GET response body.
101
+ def get_parsed(*get_args)
102
+ response = send(:get, *get_args)
103
+ parse_json(response.body)["data"]
104
+ end
105
+
106
+ # Private: parses a JSON String.
107
+ #
108
+ # string - The String of JSON.
109
+ #
110
+ # Returns a the parsed JSON as a Hash.
111
+ def parse_json(string)
112
+ JSON.parse(string)
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,30 @@
1
+ module Vinery
2
+ # Public: An array-like object that contains Records. This class inherits from
3
+ # Array.
4
+ #
5
+ # Examples
6
+ #
7
+ # collection = Collection.new
8
+ #
9
+ # collection.add(record1)
10
+ #
11
+ # collection << record2
12
+ #
13
+ # collection = Collection.new([record1, record2, record3])
14
+ class Collection < Array
15
+ # Public: Appends a new Record to the end of a Collection.
16
+ #
17
+ # record - The Record to be appended to the end of the Collection.
18
+ #
19
+ # Examples
20
+ #
21
+ # collection.push(record)
22
+ #
23
+ # Returns the array of Records.
24
+ def add(record)
25
+ raise TypeError, "the object you're tyring to add is not a Record" unless record.is_a? Record
26
+ super(record)
27
+ end
28
+ alias_method :<<, :add
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module Vinery
2
+ class InvalidCredentialsError < StandardError; end
3
+ end
@@ -0,0 +1,86 @@
1
+ module Vinery
2
+ # Public: A Vine post. Contains attributes and helper methods for working with
3
+ # a specific post.
4
+ class Record
5
+ attr_reader :description, :id, :raw, :share_url, :thumbnail_url, :user_id, :venue, :video_url
6
+
7
+ # Public: Initializes a new Record instance.
8
+ #
9
+ # data - A Hash that contains the posting's attributes. Typically this is
10
+ # a record from a parsed JSON response.
11
+ #
12
+ # Returns the new Vine instance.
13
+ def initialize(data)
14
+ @description = data["description"]
15
+ @id = data["postId"]
16
+ @raw = data
17
+ @share_url = data["shareUrl"]
18
+ @thumbnail_url = data["thumbnailUrl"]
19
+ @user_id = data["userId"]
20
+ @venue = data["venue_name"]
21
+ @video_url = data["videoUrl"]
22
+ end
23
+
24
+ # Public: Converts the Record into a Hash.
25
+ #
26
+ # Returns the String representation of the Record.
27
+ def to_h
28
+ h = {}
29
+ instance_variables.map { |iv| iv.to_s.gsub(/^@/, "") }.each do |attribute|
30
+ h[attribute] = send(attribute)
31
+ end
32
+ h
33
+ end
34
+
35
+ # Public: Converts the Record into JSON.
36
+ #
37
+ # Returns the String raw JSON data of the record.
38
+ def to_json(*a)
39
+ to_h.to_json(*a)
40
+ end
41
+
42
+ # Public: Produces a human-readable representation of the Record.
43
+ #
44
+ # Returns the String representation of the Record.
45
+ def inspect
46
+ "<#{self.class} @id=\"#{@id}\" @video_url=\"#{@video_url}\" @description=\"#{@description}\">"
47
+ end
48
+
49
+ # Public: Produces a HTML iframe embed tag.
50
+ #
51
+ # type - A Symbol that specifies the type of embed layout to display.
52
+ # Possible types are :simple and :postcard (default: :simple).
53
+ # If the type is not allowed, it will revert to :simple.
54
+ # html_attrs - A Hash of HTML attributes for the iframe tag (default: {}).
55
+ # Any keys with an underscore ("_") will be replaced with a
56
+ # hyphen ("-").
57
+ #
58
+ # Examples
59
+ #
60
+ # record.embed_tag
61
+ # # => '<iframe src=".../embed/simple"></iframe>'
62
+ #
63
+ # record.embed_tag(:postcard)
64
+ # # => '<iframe src=".../embed/postcard"></iframe>'
65
+ #
66
+ # record.embed_tag(:simple, {
67
+ # width: 600,
68
+ # height: 600,
69
+ # id: "vine-video",
70
+ # class: "class1 class2",
71
+ # data_foo: "bar"
72
+ # })
73
+ # # => '<iframe src="..." width="600" height="600" id="vine-video"
74
+ # class="class1 class2" data-foo="bar"></iframe>'
75
+ def embed_tag(type = :simple, html_attrs = {})
76
+ allowed_types = [:simple, :postcard]
77
+ type = :simple unless allowed_types.include?(type)
78
+ attrs = ""
79
+ html_attrs = attrs.each do |attr, val|
80
+ attrs << " #{attr.to_s.replace('_', '-')}=\"#{val}\""
81
+ end
82
+
83
+ "<iframe src=\"#{@share_url}/embed/#{type}\"#{attrs}></iframe>"
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,3 @@
1
+ module Vinery
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,14 @@
1
+ require "test_helper"
2
+
3
+ class ApiTest < MiniTest::Unit::TestCase
4
+ def test_invalid_login
5
+ assert_raises Vinery::InvalidCredentialsError do
6
+ Vinery::API.new("", "")
7
+ end
8
+ end
9
+
10
+ def test_tagged
11
+ vine = Vinery::API.new(ENV["VINE_USERNAME"], ENV["VINE_PASSWORD"])
12
+ refute_nil vine.tagged("funny") # TODO: make this better
13
+ end
14
+ end
@@ -0,0 +1,10 @@
1
+ require "test_helper"
2
+
3
+ class CollectionsTest < MiniTest::Unit::TestCase
4
+ def test_to_json
5
+ vinery = Vinery::API.new(ENV["VINE_USERNAME"], ENV["VINE_PASSWORD"])
6
+ records = vinery.tagged("funny")
7
+ records_json = records.to_json
8
+ assert_equal records[0].thumbnail_url, JSON.parse(records_json)[0]["thumbnail_url"]
9
+ end
10
+ end
@@ -0,0 +1,29 @@
1
+ require "test_helper"
2
+
3
+ class RecordTest < MiniTest::Unit::TestCase
4
+ def setup
5
+ @vinery = Vinery::API.new(ENV["VINE_USERNAME"], ENV["VINE_PASSWORD"])
6
+ @record = @vinery.tagged("funny").first
7
+ end
8
+
9
+ def test_to_h
10
+ record_hash = @record.to_h
11
+ record_attributes.each do |attribute|
12
+ assert_equal @record.send(attribute), record_hash[attribute]
13
+ end
14
+ end
15
+
16
+ def test_to_json
17
+ record_json = JSON.parse(@record.to_json)
18
+
19
+ record_attributes.each do |attribute|
20
+ assert_equal @record.send(attribute), record_json[attribute]
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def record_attributes
27
+ @record.instance_variables.map { |iv| iv.to_s.gsub(/^@/, "") }
28
+ end
29
+ end
@@ -0,0 +1,6 @@
1
+ require "dotenv"
2
+
3
+ Dotenv.load
4
+
5
+ require "vinery"
6
+ require "minitest/autorun"
@@ -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 'vinery/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vinery"
8
+ spec.version = Vinery::VERSION
9
+ spec.authors = ["Jake Bellacera"]
10
+ spec.email = ["jakeb@eleveninc.com"]
11
+ spec.description = "A Ruby interface for Vine."
12
+ spec.summary = "A Ruby interface for Vine."
13
+ spec.homepage = "http://github.com/jakebellacera/vinery"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "httparty", "0.12.0"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "dotenv", "0.9.0"
26
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vinery
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jake Bellacera
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.12.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.12.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '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.9.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.9.0
69
+ description: A Ruby interface for Vine.
70
+ email:
71
+ - jakeb@eleveninc.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/vinery.rb
82
+ - lib/vinery/api.rb
83
+ - lib/vinery/collection.rb
84
+ - lib/vinery/errors/invalid_credentials.rb
85
+ - lib/vinery/record.rb
86
+ - lib/vinery/version.rb
87
+ - test/api_test.rb
88
+ - test/collections_test.rb
89
+ - test/record_test.rb
90
+ - test/test_helper.rb
91
+ - vinery.gemspec
92
+ homepage: http://github.com/jakebellacera/vinery
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.0.3
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: A Ruby interface for Vine.
116
+ test_files:
117
+ - test/api_test.rb
118
+ - test/collections_test.rb
119
+ - test/record_test.rb
120
+ - test/test_helper.rb