access 1.1.7 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +2 -0
  4. data/.travis.yml +12 -0
  5. data/Guardfile +7 -0
  6. data/README.md +159 -23
  7. data/Rakefile +13 -0
  8. data/access.gemspec +6 -1
  9. data/bin/console +14 -0
  10. data/bin/setup +7 -0
  11. data/lib/access.rb +21 -10
  12. data/lib/access/api.rb +188 -64
  13. data/lib/access/autocomplete.rb +11 -0
  14. data/lib/access/campaign.rb +24 -0
  15. data/lib/access/category.rb +16 -2
  16. data/lib/access/channel.rb +24 -0
  17. data/lib/access/city_savings.rb +16 -0
  18. data/lib/access/config.rb +8 -7
  19. data/lib/access/error.rb +8 -2
  20. data/lib/access/filter.rb +30 -2
  21. data/lib/access/info.rb +13 -0
  22. data/lib/access/link.rb +17 -0
  23. data/lib/access/location.rb +17 -2
  24. data/lib/access/member.rb +11 -0
  25. data/lib/access/oauth_application.rb +31 -0
  26. data/lib/access/offer.rb +24 -20
  27. data/lib/access/redeem.rb +11 -4
  28. data/lib/access/report.rb +10 -0
  29. data/lib/access/request.rb +25 -20
  30. data/lib/access/response.rb +127 -0
  31. data/lib/access/spot.rb +28 -0
  32. data/lib/access/store.rb +16 -2
  33. data/lib/access/token.rb +18 -0
  34. data/lib/access/verify.rb +11 -2
  35. data/lib/access/version.rb +1 -1
  36. data/test/access/autocomplete_test.rb +53 -0
  37. data/test/access/category_test.rb +64 -0
  38. data/test/access/city_savings_test.rb +5 -0
  39. data/test/access/filter_test.rb +40 -0
  40. data/test/access/location_test.rb +59 -0
  41. data/test/access/member_test.rb +5 -0
  42. data/test/access/oauth_application_test.rb +91 -0
  43. data/test/access/offer_test.rb +71 -0
  44. data/test/access/redeem_test.rb +38 -0
  45. data/test/access/report_test.rb +36 -0
  46. data/test/access/store_test.rb +65 -0
  47. data/test/access/token_test.rb +35 -0
  48. data/test/access/verify_test.rb +29 -0
  49. data/test/access/version_test.rb +9 -0
  50. data/test/fixtures/autocomplete_search.yml +207 -0
  51. data/test/fixtures/autocomplete_search_categories.yml +181 -0
  52. data/test/fixtures/autocomplete_search_locations.yml +173 -0
  53. data/test/fixtures/autocomplete_search_offers.yml +181 -0
  54. data/test/fixtures/autocomplete_search_stores.yml +185 -0
  55. data/test/fixtures/category_find.yml +303 -0
  56. data/test/fixtures/category_search.yml +683 -0
  57. data/test/fixtures/category_search_fail_member_key.yml +102 -0
  58. data/test/fixtures/filter_find.yml +70 -0
  59. data/test/fixtures/filter_search.yml +195 -0
  60. data/test/fixtures/location_find.yml +923 -0
  61. data/test/fixtures/location_search.yml +378 -0
  62. data/test/fixtures/location_search_fail_member_key.yml +367 -0
  63. data/test/fixtures/national_stores.yml +4135 -0
  64. data/test/fixtures/oauth_application_find.yml +163 -0
  65. data/test/fixtures/oauth_application_search.yml +134 -0
  66. data/test/fixtures/oauth_application_search_fail_member_key.yml +268 -0
  67. data/test/fixtures/oauth_application_token_find.yml +249 -0
  68. data/test/fixtures/oauth_application_token_search.yml +98 -0
  69. data/test/fixtures/offer_find.yml +683 -0
  70. data/test/fixtures/offer_search.yml +329 -0
  71. data/test/fixtures/offer_search_fail_member_key.yml +102 -0
  72. data/test/fixtures/redeem_offer_no_redeem_type.yml +423 -0
  73. data/test/fixtures/store_find.yml +333 -0
  74. data/test/fixtures/store_search.yml +227 -0
  75. data/test/fixtures/store_search_fail_member_key.yml +102 -0
  76. data/test/fixtures/subcategory_find.yml +283 -0
  77. data/test/fixtures/token_find.yml +245 -0
  78. data/test/fixtures/token_search.yml +301 -0
  79. data/test/fixtures/verify_filter.yml +290 -0
  80. data/test/fixtures/verify_token.yml +78 -0
  81. data/test/test_helper.rb +15 -0
  82. metadata +183 -11
  83. data/test/offers/offer_test.rb +0 -5
@@ -0,0 +1,59 @@
1
+ require './test/test_helper'
2
+
3
+ class LocationTest < Minitest::Test
4
+
5
+ def get_first_location
6
+ VCR.use_cassette('location search') do
7
+ @first_location = Access::Location.search(member_key: 'API_RUBY_GEM_TEST', per_page: 1).locations.first
8
+ end
9
+ end
10
+
11
+ def test_locations_search
12
+ VCR.use_cassette('location search') do
13
+ locations_response = Access::Location.search(member_key: 'API_RUBY_GEM_TEST', per_page: 1)
14
+ assert locations_response.success
15
+ first_location = locations_response.locations.first
16
+ assert_kind_of Access::LocationResponse, locations_response
17
+ assert_kind_of Access::Link, locations_response.links
18
+ assert_kind_of Access::Info, locations_response.info
19
+ assert_kind_of Array, locations_response.locations
20
+ assert_kind_of Access::Location, first_location
21
+ assert_kind_of Access::Link, first_location.links
22
+ assert_kind_of Access::Category, first_location.location_categories.first
23
+ assert_kind_of Access::Location, first_location.physical_location
24
+ assert_kind_of Access::Store, first_location.location_store
25
+ # make these work
26
+ # assert_kind_of Access::Category, first_location.categories
27
+ # assert_kind_of Access::Store, first_location.store
28
+ # assert_kind_of Access::Store, first_location.location
29
+ # assert first_location.name
30
+ end
31
+ end
32
+
33
+ def test_locations_find
34
+ get_first_location
35
+ VCR.use_cassette('location find') do
36
+ locations_response = Access::Location.find(@first_location.location_key, member_key: 'API_RUBY_GEM_TEST')
37
+ assert locations_response.success
38
+ first_location = locations_response.locations.first
39
+ assert_kind_of Access::LocationResponse, locations_response
40
+ assert_kind_of Access::Location, first_location
41
+ assert_kind_of Access::Category, first_location.location_categories.first
42
+ assert_kind_of Access::Location, first_location.physical_location
43
+ assert_kind_of Access::Store, first_location.location_store
44
+ end
45
+ end
46
+
47
+ def test_locations_fail_member_key
48
+ VCR.use_cassette('location search fail member key') do
49
+ locations_response = Access::Location.search(query: 'pizza')
50
+ refute locations_response.success
51
+ assert_kind_of Access::LocationResponse, locations_response
52
+ assert_kind_of Access::Error, locations_response.error
53
+ assert_equal 401, locations_response.error.status_code
54
+ assert_equal "Must include a member_key to see details.", locations_response.error.message
55
+ assert_equal "Unauthorized", locations_response.error.status
56
+ end
57
+ end
58
+
59
+ end
@@ -0,0 +1,5 @@
1
+ require './test/test_helper'
2
+
3
+ class MemberTest < Minitest::Test
4
+
5
+ end
@@ -0,0 +1,91 @@
1
+ require './test/test_helper'
2
+
3
+ class OauthApplicationTest < Minitest::Test
4
+
5
+ def get_first_oauth_application
6
+ VCR.use_cassette('oauth_application search') do
7
+ @first_oauth_application = Access::OauthApplication.search(per_page: 1).oauth_applications.first
8
+ end
9
+ end
10
+
11
+ def get_first_access_token
12
+ get_first_oauth_application
13
+ VCR.use_cassette('oauth_application token search') do
14
+ @first_access_token = Access::OauthApplication.search_tokens(@first_oauth_application.id, per_page: 1).access_tokens.first
15
+ end
16
+ end
17
+
18
+ def test_oauth_applications_search
19
+ VCR.use_cassette('oauth_application search') do
20
+ oauth_applications_response = Access::OauthApplication.search(per_page: 1)
21
+ assert oauth_applications_response.success
22
+ first_oauth_application = oauth_applications_response.oauth_applications.first
23
+ assert_kind_of Access::OauthApplicationResponse, oauth_applications_response
24
+ assert_kind_of Access::Link, oauth_applications_response.links
25
+ assert_kind_of Access::Info, oauth_applications_response.info
26
+ assert_kind_of Array, oauth_applications_response.oauth_applications
27
+ assert_equal 1, oauth_applications_response.oauth_applications.count
28
+ assert_kind_of Access::OauthApplication, first_oauth_application
29
+ assert_kind_of Access::Link, first_oauth_application.links
30
+ assert_kind_of Access::Filter, first_oauth_application.filter
31
+ # has scope? method
32
+ end
33
+ end
34
+
35
+ def test_oauth_applications_find
36
+ get_first_oauth_application
37
+ VCR.use_cassette('oauth_application find') do
38
+ oauth_applications_response = Access::OauthApplication.find(@first_oauth_application.id)
39
+ assert oauth_applications_response.success
40
+ first_oauth_application = oauth_applications_response.oauth_applications.first
41
+ assert_kind_of Access::OauthApplicationResponse, oauth_applications_response
42
+ assert_kind_of Access::OauthApplication, first_oauth_application
43
+ assert_kind_of Access::Filter, first_oauth_application.filter
44
+ end
45
+ end
46
+
47
+ def test_oauth_applications_search_tokens
48
+ get_first_oauth_application
49
+ VCR.use_cassette('oauth_application token search') do
50
+ access_tokens_response = Access::OauthApplication.search_tokens(@first_oauth_application.id, per_page: 1)
51
+ assert access_tokens_response.success
52
+ first_access_token = access_tokens_response.access_tokens.first
53
+ assert_kind_of Access::TokenResponse, access_tokens_response
54
+ assert_kind_of Array, access_tokens_response.access_tokens
55
+ assert_equal 1, access_tokens_response.access_tokens.count
56
+ assert_kind_of Access::Link, first_access_token.links
57
+ refute_kind_of Hash, first_access_token.program_filter_id
58
+ # has scope? method
59
+ end
60
+ end
61
+
62
+ def test_oauth_applications_find_token
63
+ get_first_access_token
64
+ VCR.use_cassette('oauth_application token find') do
65
+ access_tokens_response = Access::OauthApplication.find_token(@first_access_token.application_id, @first_access_token.oauth_access_token_id)
66
+ assert access_tokens_response.success
67
+ first_access_token = access_tokens_response.access_tokens.first
68
+ assert_kind_of Access::TokenResponse, access_tokens_response
69
+ assert_kind_of Array, access_tokens_response.access_tokens
70
+ assert_equal 1, access_tokens_response.access_tokens.count
71
+ refute_kind_of Hash, first_access_token.program_filter_id
72
+ # has scope? method
73
+ end
74
+ end
75
+
76
+ def test_oauth_applications_create_token
77
+
78
+ end
79
+
80
+ def test_oauth_applications_create
81
+
82
+ end
83
+
84
+ def test_oauth_applications_update
85
+
86
+ end
87
+
88
+ def test_oauth_applications_delete
89
+
90
+ end
91
+ end
@@ -0,0 +1,71 @@
1
+ require './test/test_helper'
2
+
3
+ class OfferTest < Minitest::Test
4
+
5
+ def get_first_offer
6
+ VCR.use_cassette('offer search') do
7
+ @first_offer = Access::Offer.search(query: 'pizza', member_key: 'API_RUBY_GEM_TEST', per_page: 1).offers.first
8
+ end
9
+ end
10
+
11
+ def test_offers_search
12
+ assert_equal Access.config.access_token, ENV['ACCESS_TOKEN']
13
+
14
+ VCR.use_cassette('offer search') do
15
+ offers_response = Access::Offer.search(query: 'pizza', member_key: 'API_RUBY_GEM_TEST', per_page: 1)
16
+ first_offer = offers_response.offers.first
17
+ assert offers_response.success
18
+ assert_kind_of Access::OfferResponse, offers_response
19
+ assert_kind_of Access::Link, offers_response.links
20
+ assert_kind_of Access::Info, offers_response.info
21
+ assert_kind_of Array, offers_response.offers
22
+ assert_kind_of Access::Offer, first_offer
23
+ assert_kind_of Access::Category, first_offer.categories.first
24
+ assert_kind_of Access::Store, first_offer.offer_store
25
+ assert_kind_of Access::Location, first_offer.location
26
+ assert_kind_of Access::Link, first_offer.links
27
+ end
28
+ end
29
+
30
+ def test_offers_find
31
+ get_first_offer
32
+ VCR.use_cassette('offer find') do
33
+ offers_response = Access::Offer.find(@first_offer.offer_key, query: 'pizza', member_key: 'API_RUBY_GEM_TEST')
34
+ first_offer = offers_response.offers.first
35
+ assert offers_response.success
36
+ assert_kind_of Access::OfferResponse, offers_response
37
+ assert_kind_of Access::Offer, first_offer
38
+ end
39
+ end
40
+
41
+ def test_offers_extra_methods
42
+ VCR.use_cassette('offer search') do
43
+ offers_response = Access::Offer.search(query: 'pizza', member_key: 'API_RUBY_GEM_TEST', per_page: 1)
44
+ first_offer = offers_response.offers.first
45
+ assert offers_response.success
46
+ # location
47
+ assert_equal first_offer.offer_store.physical_location, first_offer.location
48
+ # store
49
+ assert_equal first_offer.offer_store, first_offer.store
50
+ end
51
+ end
52
+
53
+ def test_offers_fail_member_key
54
+ VCR.use_cassette('offer search fail member key') do
55
+ offers_response = Access::Offer.search(query: 'pizza')
56
+ refute offers_response.success
57
+ assert_kind_of Access::OfferResponse, offers_response
58
+ assert_kind_of Access::Error, offers_response.error
59
+ assert_equal 401, offers_response.error.status_code
60
+ assert_equal "Must include a member_key to see details.", offers_response.error.message
61
+ assert_equal "Unauthorized", offers_response.error.status
62
+ end
63
+ end
64
+
65
+ def test_offers_fail_no_access_token
66
+ orginal_token = ENV['ACCESS_TOKEN']
67
+ Access.config.access_token = ENV['ACCESS_TOKEN'] = nil
68
+ assert_raises(Access::Error::NoAccessToken) { Access::Offer.search(query: 'pizza', member_key: 'API_RUBY_GEM_TEST') }
69
+ Access.config.access_token = ENV['ACCESS_TOKEN'] = orginal_token
70
+ end
71
+ end
@@ -0,0 +1,38 @@
1
+ require './test/test_helper'
2
+
3
+ class RedeemTest < Minitest::Test
4
+
5
+ def get_first_offer
6
+ VCR.use_cassette('offer search') do
7
+ @first_offer = Access::Offer.search(query: 'pizza', member_key: 'API_RUBY_GEM_TEST', per_page: 1).offers.first
8
+ end
9
+ end
10
+
11
+ def test_redeem_offer_no_redeem_type
12
+ get_first_offer
13
+ VCR.use_cassette('redeem offer no redeem type') do
14
+ redeem_response = Access::Redeem.redeem_offer(@first_offer.offer_key, nil, member_key: 'API_RUBY_GEM_TEST')
15
+ assert redeem_response.success
16
+ assert_kind_of Access::RedeemResponse, redeem_response
17
+ assert_kind_of Array, redeem_response.links
18
+ assert_kind_of Access::Link, redeem_response.links.first
19
+ assert redeem_response.links.first.href
20
+ assert redeem_response.links.first.rel
21
+ end
22
+ end
23
+
24
+
25
+ def test_redeem_offer_with_redeem_type
26
+ get_first_offer
27
+ VCR.use_cassette('redeem offer no redeem type') do
28
+ redeem_response = Access::Redeem.redeem_offer(@first_offer.offer_key, @first_offer.redemption_methods.first, member_key: 'API_RUBY_GEM_TEST')
29
+ assert redeem_response.success
30
+ assert_kind_of Access::RedeemResponse, redeem_response
31
+ assert_kind_of Array, redeem_response.links
32
+ assert redeem_response.content_type
33
+ assert redeem_response.redemption_method
34
+ assert redeem_response.details
35
+ assert redeem_response.details.link
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,36 @@
1
+ require './test/test_helper'
2
+
3
+ class ReportTest < Minitest::Test
4
+
5
+ # def get_first_report
6
+ # VCR.use_cassette('report search') do
7
+ # @first_report = Access::Report.search(member_key: 'API_RUBY_GEM_TEST', per_page: 1).reports.first
8
+ # end
9
+ # end
10
+
11
+ # def test_reports_search
12
+ # VCR.use_cassette('report search') do
13
+ # reports_response = Access::Report.search(member_key: 'API_RUBY_GEM_TEST', per_page: 1)
14
+ # assert reports_response.success
15
+ # first_report = reports_response.reports.first
16
+ # assert_kind_of Access::ReportResponse, reports_response
17
+ # assert_kind_of Access::Link, reports_response.links
18
+ # assert_kind_of Access::Info, reports_response.info
19
+ # assert_kind_of Array, reports_response.reports
20
+ # assert_kind_of Access::Report, first_report
21
+ # assert_kind_of Access::Link, first_report.links
22
+ # end
23
+ # end
24
+
25
+ # def test_reports_find
26
+ # get_first_report
27
+ # VCR.use_cassette('report find') do
28
+ # reports_response = Access::Report.find(@first_report.report_key, member_key: 'API_RUBY_GEM_TEST')
29
+ # assert reports_response.success
30
+ # first_report = reports_response.reports.first
31
+ # assert_kind_of Access::ReportResponse, reports_response
32
+ # assert_kind_of Access::Report, first_report
33
+ # end
34
+ # end
35
+
36
+ end
@@ -0,0 +1,65 @@
1
+ require './test/test_helper'
2
+
3
+ class StoreTest < Minitest::Test
4
+
5
+ def get_first_store
6
+ VCR.use_cassette('store search') do
7
+ @first_store = Access::Store.search(member_key: 'API_RUBY_GEM_TEST', per_page: 1).stores.first
8
+ end
9
+ end
10
+
11
+ def test_stores_search
12
+ VCR.use_cassette('store search') do
13
+ stores_response = Access::Store.search(member_key: 'API_RUBY_GEM_TEST', per_page: 1)
14
+ assert stores_response.success
15
+ first_store = stores_response.stores.first
16
+ assert_kind_of Access::StoreResponse, stores_response
17
+ assert_kind_of Access::Link, stores_response.links
18
+ assert_kind_of Access::Info, stores_response.info
19
+ assert_kind_of Array, stores_response.stores
20
+ assert_kind_of Access::Store, first_store
21
+ assert_kind_of Access::Link, first_store.links
22
+ assert_kind_of Access::Category, first_store.store_categories.first
23
+
24
+ # things to add
25
+ # assert_kind_of Access::Category, first_store.categories
26
+ end
27
+ end
28
+
29
+ def test_stores_find
30
+ get_first_store
31
+ VCR.use_cassette('store find') do
32
+ stores_response = Access::Store.find(@first_store.store_key, member_key: 'API_RUBY_GEM_TEST')
33
+ assert stores_response.success
34
+ first_store = stores_response.stores.first
35
+ # pp stores_response.inspect
36
+ assert_kind_of Access::StoreResponse, stores_response
37
+ assert_kind_of Access::Store, first_store
38
+ assert_kind_of Access::Link, first_store.links
39
+ assert_kind_of Access::Category, first_store.store_categories.first
40
+ end
41
+ end
42
+
43
+ def test_national_stores_find
44
+ VCR.use_cassette('national stores') do
45
+ stores_response = Access::Store.national(per_page: 1, member_key: 'API_RUBY_GEM_TEST')
46
+ assert stores_response.success
47
+ first_store = stores_response.stores.first
48
+ assert_kind_of Access::StoreResponse, stores_response
49
+ assert_kind_of Access::Store, first_store
50
+ end
51
+ end
52
+
53
+ def test_stores_fail_member_key
54
+ VCR.use_cassette('store search fail member key') do
55
+ stores_response = Access::Store.search(query: 'pizza')
56
+ refute stores_response.success
57
+ assert_kind_of Access::StoreResponse, stores_response
58
+ assert_kind_of Access::Error, stores_response.error
59
+ assert_equal 401, stores_response.error.status_code
60
+ assert_equal "Must include a member_key to see details.", stores_response.error.message
61
+ assert_equal "Unauthorized", stores_response.error.status
62
+ end
63
+ end
64
+
65
+ end
@@ -0,0 +1,35 @@
1
+ require './test/test_helper'
2
+
3
+ class TokenTest < Minitest::Test
4
+
5
+ def get_first_token
6
+ VCR.use_cassette('token search') do
7
+ @first_token = Access::Token.search(per_page: 1).oauth_tokens.first
8
+ end
9
+ end
10
+
11
+ def test_tokens_search
12
+ VCR.use_cassette('token search') do
13
+ tokens_response = Access::Token.search(per_page: 1)
14
+ assert tokens_response.success
15
+ first_token = tokens_response.oauth_tokens.first
16
+ assert_kind_of Access::TokenResponse, tokens_response
17
+ assert_kind_of Access::Link, tokens_response.links
18
+ assert_kind_of Access::Info, tokens_response.info
19
+ assert_kind_of Array, tokens_response.oauth_tokens
20
+ assert_kind_of Access::Token, first_token
21
+ assert_kind_of Access::Link, first_token.links
22
+ end
23
+ end
24
+
25
+ def test_tokens_find
26
+ get_first_token
27
+ VCR.use_cassette('token find') do
28
+ tokens_response = Access::Token.find(@first_token.token)
29
+ assert tokens_response.success
30
+ assert_kind_of Access::TokenResponse, tokens_response
31
+ assert_kind_of Access::Token, tokens_response.oauth_token
32
+ end
33
+ end
34
+
35
+ end
@@ -0,0 +1,29 @@
1
+ require './test/test_helper'
2
+
3
+ class VerifyTest < Minitest::Test
4
+
5
+ def test_verify_token
6
+ VCR.use_cassette('verify token') do
7
+ verify_response = Access::Verify.token
8
+ assert verify_response.success
9
+ assert_kind_of Access::VerifyResponse, verify_response
10
+ assert_kind_of Access::Verify, verify_response.oauth_access_token
11
+ end
12
+ end
13
+
14
+ def test_verify_filter
15
+ VCR.use_cassette('verify filter') do
16
+ single_filter = '{"program_filter": {"offers": [{"or":[{"terms":{"categories.category_key":[ 39, 1007, 1008, 1009, 1010, 1011, 1012 ] } }, {"terms":{"categories.category_parent_key":[ 39, 1007, 1008, 1009, 1010, 1011, 1012]} } ]}, {"not": {"or": [{"terms":{"categories.category_key":[ 1007 ] } }, {"terms":{"categories.category_parent_key":[ 1007 ] } } ] } } ] } }'
17
+ verify_response = Access::Verify.filter single_filter
18
+ assert verify_response.success
19
+ assert_kind_of Access::VerifyResponse, verify_response
20
+ assert_kind_of Access::Verify, verify_response.categories
21
+ assert_kind_of Access::Verify, verify_response.locations
22
+ assert_kind_of Access::Verify, verify_response.stores
23
+ assert_kind_of Access::Verify, verify_response.offers
24
+ assert_kind_of Access::Redeem, verify_response.offers.redemption_methods.first
25
+ assert_kind_of Access::Category, verify_response.offers.categories.first
26
+ end
27
+ end
28
+
29
+ end
@@ -0,0 +1,9 @@
1
+ require './test/test_helper'
2
+
3
+ class VersionTest < Minitest::Test
4
+
5
+ def test_must_be_defined
6
+ assert Access::VERSION
7
+ end
8
+
9
+ end