twenty20 0.0.2
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.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/README.md +49 -0
- data/Rakefile +3 -0
- data/lib/twenty20.rb +51 -0
- data/lib/twenty20/challenge.rb +14 -0
- data/lib/twenty20/item.rb +19 -0
- data/lib/twenty20/version.rb +3 -0
- data/spec/challenge_spec.rb +35 -0
- data/spec/client_spec.rb +47 -0
- data/spec/item_spec.rb +47 -0
- data/spec/spec_helper.rb +1 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: aad59c3f8645620c5b0390527f4cadeebfa0a21a
|
4
|
+
data.tar.gz: d8e020a810e145f5228240c68c39ded8f3463842
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 16ff75c3315438401164caef578eb839d79674e134e74a62b09c1c1da7f1bf363964aafe4148e304dc666c72a11f3993a88f9d368c6ff4298d38971fdec4262f
|
7
|
+
data.tar.gz: a90218f44099818327fdce709da9c035497aec1bc270db9b3e4a9bc844f01127a5e227d0e9a3c777c552407202a1a1963e388d377228fd13111bdb3a46f3d7e5
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Twenty20
|
2
|
+
Api client for interacting with Twenty20's internal API. Still in development
|
3
|
+
|
4
|
+
Example uses
|
5
|
+
- query featured items
|
6
|
+
- query items you have 'loved'
|
7
|
+
- query challenges
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'twenty20'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install twenty20
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
API client for interacting with Twenty20s internal API.
|
28
|
+
|
29
|
+
Instantiate a new client
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
client = Twenty20::Client.new
|
33
|
+
```
|
34
|
+
Get Featured items
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
client.get_featured_items()
|
38
|
+
```
|
39
|
+
```ruby
|
40
|
+
[#<Item:0x007feff9212348 @caption="Red Canoes on Lake Louise", @id=45414069, @source_name="upload", @image_url="https://res.cloudinary.com/twenty20/image/upload/t_standard-fit/photos/cf34293d-1eeb-47a7-94c7-99397dce4c15.jpg", @featured_at="2014-11-29T22:40:04Z", @user_first_name=nil, @user_last_name=nil, @user_avatar_url=nil, @username=nil, @display_name=nil>, #<Item:0x007feff9212190 @caption=nil, @id=49291337, @source_name="instagram", @image_url="http://scontent-b.cdninstagram.com/hphotos-xpa1/t51.2885-15/1742594_280292302171814_502487005_n.jpg", @featured_at="2014-11-29T22:20:02Z"...]
|
41
|
+
```
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
1. Fork it ( https://github.com/AlexWheeler/twenty20_API/fork )
|
46
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
47
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
48
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
49
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/twenty20.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require "twenty20/version"
|
2
|
+
require "twenty20/item"
|
3
|
+
require "twenty20/challenge"
|
4
|
+
require "httparty"
|
5
|
+
|
6
|
+
module Twenty20
|
7
|
+
class Client
|
8
|
+
include HTTParty
|
9
|
+
BASE_URI = "https://api-v2.twenty20.com/"
|
10
|
+
|
11
|
+
def get_featured_items
|
12
|
+
featured_route = "items/featured"
|
13
|
+
featured_params = "?featured=true"
|
14
|
+
resource = build_route(featured_route, featured_params)
|
15
|
+
response = self.class.get(resource)
|
16
|
+
if(response.code == 200)
|
17
|
+
item_collection = to_item_collection(response)
|
18
|
+
item_collection
|
19
|
+
else
|
20
|
+
"Error"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_challenges
|
25
|
+
challenges_route = "/challenges/open-for-submissions"
|
26
|
+
resource = build_route(challenges_route)
|
27
|
+
response = self.class.get(resource)
|
28
|
+
if(response.code == 200)
|
29
|
+
challenge_collection = to_challenge_collection(response)
|
30
|
+
challenge_collection
|
31
|
+
else
|
32
|
+
"Error"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def to_item_collection(response) #creates Item objects out of each element in the response object and returns this new array
|
39
|
+
response.parsed_response["items"].collect {|item| Item.new(item)}
|
40
|
+
end
|
41
|
+
|
42
|
+
def to_challenge_collection(response)
|
43
|
+
response.parsed_response["challenges"].collect {|challenge| Challenge.new(challenge)}
|
44
|
+
end
|
45
|
+
|
46
|
+
def build_route(uri, params = "")
|
47
|
+
route = BASE_URI + uri + params
|
48
|
+
route
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Twenty20
|
2
|
+
class Challenge
|
3
|
+
attr_reader :slug, :name, :description, :starts_at, :ends_at, :submission_count
|
4
|
+
|
5
|
+
def initialize(attributes = {})
|
6
|
+
@slug = attributes["slug"]
|
7
|
+
@name = attributes["name"]
|
8
|
+
@description = attributes["description"]
|
9
|
+
@starts_at = attributes["starts_at"]
|
10
|
+
@ends_at = attributes["ends_at"]
|
11
|
+
@submission_count = attributes["submission_count"]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Twenty20
|
2
|
+
class Item
|
3
|
+
attr_reader :caption, :id, :source_name, :image_url, :featured_at, :user_first_name,
|
4
|
+
:user_last_name, :user_avatar_url, :username, :display_name
|
5
|
+
def initialize(attributes = {}) #set default so attributes will default to nil and not throw exception if not present
|
6
|
+
@caption = attributes["caption"]
|
7
|
+
@id = attributes["id"]
|
8
|
+
@source_name = attributes["source_name"]
|
9
|
+
@image_url = attributes["standard_url"]
|
10
|
+
@featured_at = attributes["featured_at"]
|
11
|
+
@user_first_name = attributes["first_name"]
|
12
|
+
@user_last_name = attributes["last_name"]
|
13
|
+
@user_avatar_url = attributes["avatar"]
|
14
|
+
@username = attributes["username"]
|
15
|
+
@display_name = attributes["display_name"]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Twenty20::Challenge do
|
4
|
+
describe "slug" do
|
5
|
+
|
6
|
+
before(:all) do
|
7
|
+
attributes = {"slug" => "technology-challenge"}
|
8
|
+
@challenge = Twenty20::Challenge.new(attributes)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "returns the slug for the challenge" do
|
12
|
+
expect(@challenge.slug).to eq("technology-challenge")
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should be immutable" do
|
16
|
+
expect{@challenge.slug = "some new slug"}.to raise_error(NoMethodError)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "name" do
|
21
|
+
it "returns the name of the challenge" do
|
22
|
+
attributes = {"name" => "technology"}
|
23
|
+
challenge = Twenty20::Challenge.new(attributes)
|
24
|
+
expect(challenge.name).to eq("technology")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "description" do
|
29
|
+
it "returns the description of the challenge" do
|
30
|
+
attributes = {"description" => "really cool challenge"}
|
31
|
+
challenge = Twenty20::Challenge.new(attributes)
|
32
|
+
expect(challenge.description).to eq("really cool challenge")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/spec/client_spec.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Twenty20::Client do
|
4
|
+
|
5
|
+
describe "BASE_URI" do
|
6
|
+
it "returns the base uri for the api" do
|
7
|
+
expect(Twenty20::Client::BASE_URI).to eq("https://api-v2.twenty20.com/")
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "get_featured_items" do
|
12
|
+
|
13
|
+
before(:all) do
|
14
|
+
@client = Twenty20::Client.new
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns an Array" do
|
18
|
+
expect(@client.get_featured_items.class).to eq(Array)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns an Array of Item objects" do
|
22
|
+
expect(@client.get_featured_items[0].class).to eq(Twenty20::Item)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns error if status is not 200" do
|
26
|
+
fake_response = double
|
27
|
+
fake_response.stub(:code) { 400 }
|
28
|
+
Twenty20::Client.stub(:get) { fake_response }
|
29
|
+
response = @client.get_featured_items
|
30
|
+
expect(response).to eq("Error")
|
31
|
+
end
|
32
|
+
|
33
|
+
it "doesnt return error if status is 200" do
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "get_challenges" do
|
38
|
+
before(:all) do
|
39
|
+
@client = Twenty20::Client.new
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should return an array of challenge objects" do
|
43
|
+
response = @client.get_challenges
|
44
|
+
expect(response.class).to eq(Array);
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/spec/item_spec.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Twenty20::Item do
|
4
|
+
describe "category" do
|
5
|
+
it "returns the items category" do
|
6
|
+
attributes = {"caption" => "mobile photography ftw"}
|
7
|
+
item = Twenty20::Item.new(attributes)
|
8
|
+
expect(item.caption).to eq("mobile photography ftw")
|
9
|
+
end
|
10
|
+
|
11
|
+
it "returns nil when not present" do
|
12
|
+
item = Twenty20::Item.new
|
13
|
+
expect(item.caption).to eq(nil)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should be immutable" do
|
17
|
+
item = Twenty20::Item.new
|
18
|
+
expect{item.category = "not allowed"}.to raise_error(NoMethodError)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "id" do
|
23
|
+
it "returns the items id " do
|
24
|
+
attributes = {"id" => 1}
|
25
|
+
item = Twenty20::Item.new(attributes)
|
26
|
+
expect(item.id).to eq(1)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "returns nil when not present" do
|
30
|
+
item = Twenty20::Item.new
|
31
|
+
expect(item.id).to eq(nil)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "source_name" do
|
36
|
+
it "returns the items id " do
|
37
|
+
attributes = {"source_name" => "Instagram"}
|
38
|
+
item = Twenty20::Item.new(attributes)
|
39
|
+
expect(item.source_name).to eq("Instagram")
|
40
|
+
end
|
41
|
+
|
42
|
+
it "returns nil when not present" do
|
43
|
+
item = Twenty20::Item.new
|
44
|
+
expect(item.source_name).to eq(nil)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'twenty20'
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: twenty20
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alex Wheeler
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-30 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'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '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.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
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
|
+
description: API client to explore Twenty20
|
70
|
+
email:
|
71
|
+
- afwheeler92@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- Gemfile
|
77
|
+
- README.md
|
78
|
+
- Rakefile
|
79
|
+
- lib/twenty20.rb
|
80
|
+
- lib/twenty20/challenge.rb
|
81
|
+
- lib/twenty20/item.rb
|
82
|
+
- lib/twenty20/version.rb
|
83
|
+
- spec/challenge_spec.rb
|
84
|
+
- spec/client_spec.rb
|
85
|
+
- spec/item_spec.rb
|
86
|
+
- spec/spec_helper.rb
|
87
|
+
homepage: ''
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.2.2
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: explore twenty20
|
111
|
+
test_files:
|
112
|
+
- spec/challenge_spec.rb
|
113
|
+
- spec/client_spec.rb
|
114
|
+
- spec/item_spec.rb
|
115
|
+
- spec/spec_helper.rb
|