clyp 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 272eb4aaf10f9a44dc16bfc70831b851e22276d2
4
+ data.tar.gz: 6e2a6d5c26161ac26dff4e66b101cc4286619620
5
+ SHA512:
6
+ metadata.gz: e659faddf42462c1922885a14196fcca24159c3d2f29e668d7a7defa768620544e414f0545ea9c2fb4e1e9bffce1aea5c9d3ed11d560d2b1e4348e956a0a27d8
7
+ data.tar.gz: a6537358a5d9f8d2425a18b560af0d16475965450ff0a953f36274250088d846d78c1143e370cdb3796e467bd5218fffe661d4be14ebf244a3ad1c4099a6570d
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.idea
11
+ /.idea/*
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in clypit.gemspec
4
+ gemspec
@@ -0,0 +1,27 @@
1
+ Copyright (c) 2015, Alexander Lozada
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+
10
+ * Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation
12
+ and/or other materials provided with the distribution.
13
+
14
+ * Neither the name of tumbot nor the names of its
15
+ contributors may be used to endorse or promote products derived from
16
+ this software without specific prior written permission.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,86 @@
1
+ # Clyp
2
+
3
+ Clyp is an unofficial API wrapper for the audio sharing website http://clyp.it With this gem, you can view, search, and upload your own files.
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'clyp'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install clyp
21
+
22
+ ## Usage
23
+
24
+ To use the `clyp` gem, include this in your files
25
+
26
+ require `clyp`
27
+
28
+ ### Uploading a file
29
+
30
+ First, create a `TrackUpload` object, and set the parameters to your liking.
31
+
32
+ track = Clyp::TrackUpload.new(file: File.new('../test/files/sample.mp3'), title: 'Test', description: '#cool test')
33
+
34
+ Create a client object to manage the API.
35
+
36
+ client = Clyp::Client.new
37
+
38
+ Finally, Pass in your `TrackUpload` object
39
+
40
+ my_upload = client.upload(track)
41
+
42
+ The upload function will return a `TrackUser` object. For instance, to access the new `url`, perform the following
43
+
44
+ my_upload.url
45
+ >> https://clyp.it/qvneogei
46
+
47
+ You can also access direct MP3 links, the date uploaded, and more.
48
+
49
+
50
+ ### More API functions
51
+
52
+ Search for tracks:
53
+
54
+ client = Clyp::Client.new
55
+ client.search 'guitar'
56
+
57
+ Get random tracks:
58
+
59
+ client = Clyp::Client.new
60
+ client.random(count: 5)
61
+
62
+ Get popular tracks:
63
+
64
+ client = Clyp::Client.new
65
+ client.popular(count: 3)
66
+
67
+ Chain functions:
68
+
69
+ client = Clyp::Client.new
70
+ client.get(id: client.search('piano').first.id)
71
+
72
+ There are more functions available in the documentation.
73
+
74
+ ## Development
75
+
76
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
77
+
78
+ 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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
79
+
80
+ ## Contributing
81
+
82
+ 1. Fork it ( https://github.com/piedoom/clyp/fork )
83
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
84
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
85
+ 4. Push to the branch (`git push origin my-new-feature`)
86
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "clyp"
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,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'clyp/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "clyp"
8
+ spec.version = Clyp::VERSION
9
+ spec.authors = ["Alexander Lozada"]
10
+ spec.email = ["alexanderpaullozada@gmail.com"]
11
+
12
+ if spec.respond_to?(:metadata)
13
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
14
+ end
15
+
16
+ spec.summary = %q{An API wrapper for the audio sharing website, clyp.it}
17
+ spec.homepage = "https://github.com/piedoom/clyp-ruby"
18
+ spec.license = "BSD-3-Clause"
19
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.8"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+
27
+ spec.add_development_dependency "vcr"
28
+ spec.add_development_dependency "webmock"
29
+ spec.add_dependency "faraday"
30
+ spec.add_dependency "rest-client"
31
+ spec.add_dependency "json"
32
+ end
@@ -0,0 +1,9 @@
1
+ require_relative "clyp/version"
2
+ require_relative 'clyp/client'
3
+ require_relative 'clyp/track'
4
+ require_relative 'clyp/track_upload'
5
+ require_relative 'clyp/track_user'
6
+ require_relative 'clyp/soundwave'
7
+ require_relative 'clyp/list_item'
8
+ require 'faraday'
9
+
@@ -0,0 +1,105 @@
1
+ require 'json'
2
+ require 'rest-client'
3
+ API_BASE = "https://api.clyp.it"
4
+ UPLOAD_BASE = "https://upload.clyp.it/upload"
5
+
6
+ module Clyp
7
+ class Client
8
+ # uploads a TrackUpload object, returns a TrackUser object
9
+ def upload track
10
+ if track.playlist_id and track.playlist_token
11
+ response = JSON.parse(RestClient.post(UPLOAD_BASE, audioFile: track.file, title: track.title, playlistId: track.playlist_id,
12
+ playlistUploadToken: track.playlist_token, order: track.order, description: track.description,
13
+ longitude: track.longitude, latitude: track.latitude))
14
+ else
15
+ response = JSON.parse(RestClient.post(UPLOAD_BASE, audioFile: track.file, title: track.title,
16
+ order: track.order, description: track.description, longitude: track.longitude, latitude: track.latitude))
17
+ end
18
+ TrackUser.new(response)
19
+ end
20
+
21
+ # get song with specific id
22
+ def get (id:)
23
+ response = Faraday.get("#{API_BASE}/#{id}")
24
+ attributes = JSON.parse(response.body)
25
+ Track.new(attributes)
26
+ end
27
+
28
+ # returns a Soundwave object with peak data
29
+ def soundwave (id:)
30
+ response = Faraday.get("#{API_BASE}/#{id}/soundwave")
31
+ attributes = JSON.parse(response.body)
32
+ Soundwave.new(attributes)
33
+ end
34
+
35
+ # returns an array of ListItem objects of categories
36
+ def category_list
37
+ response = Faraday.get("#{API_BASE}/categorylist")
38
+ attributes = JSON.parse(response.body)
39
+ result = Array.new
40
+ attributes.each do |attrs|
41
+ result << ListItem.new(attrs)
42
+ end
43
+ result
44
+ end
45
+
46
+ # returns 20 tracks from a specified search in an array of Track objects
47
+ def search term
48
+ response = Faraday.get("#{API_BASE}/categorylist/#{term}")
49
+ attributes = JSON.parse(response.body)
50
+ assemble_tracks attributes
51
+ end
52
+
53
+ # returns featured tracks in an array of Track objects
54
+ def featured (count: 10)
55
+ response = Faraday.get("#{API_BASE}/featuredlist/featured?count=#{count}")
56
+ attributes = JSON.parse(response.body)
57
+ assemble_tracks attributes
58
+ end
59
+
60
+ # returns popular tracks in an array of Track objects
61
+ def popular (count: 10)
62
+ response = Faraday.get("#{API_BASE}/featuredlist/popular?count=#{count}")
63
+ attributes = JSON.parse(response.body)
64
+ assemble_tracks attributes
65
+ end
66
+
67
+ # returns random tracks in an array of Track objects
68
+ def random (count: 10)
69
+ response = Faraday.get("#{API_BASE}/featuredlist/random?count=#{count}")
70
+ attributes = JSON.parse(response.body)
71
+ assemble_tracks attributes
72
+ end
73
+
74
+ # returns recent tracks in an array of Track objects
75
+ def recent (count: 10)
76
+ response = Faraday.get("#{API_BASE}/featuredlist/recent?count=#{count}")
77
+ attributes = JSON.parse(response.body)
78
+ assemble_tracks attributes
79
+ end
80
+
81
+ # TODO:
82
+ #def get_playlist (id: )
83
+ # response = Faraday.get("#{API_BASE}/playlist/#{id}")
84
+ # attributes = JSON.parse(response.body)
85
+ #end
86
+
87
+ # returns an array of nearby tracks
88
+ def featured_nearby (count: 10, longitude: 0, latitude: 0)
89
+ response = Faraday.get("#{API_BASE}/featuredlist/nearby?count=#{count}&longitude=#{longitude}&latitude=#{latitude}")
90
+ attributes = JSON.parse(response.body)
91
+ assemble_tracks attributes
92
+ end
93
+
94
+ private
95
+
96
+ def assemble_tracks attributes
97
+ result = Array.new
98
+ attributes.each do |attrs|
99
+ result << Track.new(attrs)
100
+ end
101
+ result
102
+ end
103
+
104
+ end
105
+ end
@@ -0,0 +1,11 @@
1
+ module Clyp
2
+ class ListItem
3
+ VALID_OPTIONS_KEYS = [:title, :location]
4
+ attr_accessor *VALID_OPTIONS_KEYS
5
+
6
+ def initialize(t)
7
+ @title = t['Title']
8
+ @location = t['Location']
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ module Clyp
2
+ class Soundwave
3
+ VALID_OPTIONS_KEYS = [:data]
4
+ attr_accessor *VALID_OPTIONS_KEYS
5
+
6
+ def initialize(t)
7
+ @data = t
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,26 @@
1
+ module Clyp
2
+ class Track
3
+ VALID_OPTIONS_KEYS = [:status, :comments_enabled, :category, :id, :title, :description, :duration, :url, :url_secure_mp3,
4
+ :url_mp3, :url_ogg, :url_secure_ogg, :longitude, :latitude, :date]
5
+ attr_accessor *VALID_OPTIONS_KEYS
6
+
7
+ def initialize(t={})
8
+ @status = t['Status']
9
+ @comments_enabled = t['CommentsEnabled']
10
+ @category = t['Category']
11
+ @id = t['AudioFileId']
12
+ @title = t['Title']
13
+ @description = t['Description']
14
+ @duration = t['Duration']
15
+ @url = t['Url']
16
+ @url_mp3 = t['Mp3Url']
17
+ @url_secure_mp3 = t['SecureMp3Url']
18
+ @url_ogg = t['OggUrl']
19
+ @url_secure_ogg = t['SecureOggUrl']
20
+ @longitude = t['Longitude']
21
+ @latitude = t['Latitude']
22
+ @date = t['DateCreated']
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,18 @@
1
+ module Clyp
2
+ class TrackUpload
3
+ VALID_OPTIONS_KEYS = [:file, :playlist_id, :playlist_token, :order, :description, :longitude, :latitude, :title]
4
+ attr_accessor *VALID_OPTIONS_KEYS
5
+
6
+ def initialize(t={})
7
+ @file = t[:file]
8
+ @playlist_id = t[:playlist_id]
9
+ @playlist_token = t[:playlist_token]
10
+ @order = t[:order]
11
+ @description = t[:description]
12
+ @longitude = t[:longitude]
13
+ @latitude = t[:latitude]
14
+ @title = t[:title]
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,14 @@
1
+ module Clyp
2
+ VALID_OPTIONS_KEYS = [:successful, :message, :playlist_id, :playlist_token]
3
+ attr_accessor *VALID_OPTIONS_KEYS
4
+
5
+ class TrackUser < Track
6
+ def initialize t
7
+ super(t)
8
+ @successful = t[:successful]
9
+ @message = t[:message]
10
+ @playlist_id = t[:playlist_id]
11
+ @playlist_token = t[:playlist_token]
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module Clyp
2
+ VERSION = "0.1.1"
3
+ end
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: clyp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Lozada
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-01-15 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.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
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: vcr
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: webmock
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: rest-client
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
+ - !ruby/object:Gem::Dependency
98
+ name: json
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description:
112
+ email:
113
+ - alexanderpaullozada@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".travis.yml"
120
+ - Gemfile
121
+ - LICENSE.txt
122
+ - README.md
123
+ - Rakefile
124
+ - bin/console
125
+ - bin/setup
126
+ - clyp.gemspec
127
+ - lib/clyp.rb
128
+ - lib/clyp/client.rb
129
+ - lib/clyp/list_item.rb
130
+ - lib/clyp/soundwave.rb
131
+ - lib/clyp/track.rb
132
+ - lib/clyp/track_upload.rb
133
+ - lib/clyp/track_user.rb
134
+ - lib/clyp/version.rb
135
+ homepage: https://github.com/piedoom/clyp-ruby
136
+ licenses:
137
+ - BSD-3-Clause
138
+ metadata:
139
+ allowed_push_host: https://rubygems.org
140
+ post_install_message:
141
+ rdoc_options: []
142
+ require_paths:
143
+ - lib
144
+ required_ruby_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ requirements: []
155
+ rubyforge_project:
156
+ rubygems_version: 2.4.6
157
+ signing_key:
158
+ specification_version: 4
159
+ summary: An API wrapper for the audio sharing website, clyp.it
160
+ test_files: []